diff options
author | rubenwardy <rw@rubenwardy.com> | 2018-05-12 17:28:04 +0100 |
---|---|---|
committer | rubenwardy <rw@rubenwardy.com> | 2018-05-12 17:28:04 +0100 |
commit | db3d63d91a7e97fe03875307640033bd0e50a8d7 (patch) | |
tree | 6d00c7a1807df2e5f8216fb06f90e6d881581c0e /app/tasks/importtasks.py | |
parent | 2b0f61b453a3409def14a6ef193cb00b0692990c (diff) | |
download | cheatdb-db3d63d91a7e97fe03875307640033bd0e50a8d7.tar.xz |
Add more metadata to importer
Diffstat (limited to 'app/tasks/importtasks.py')
-rw-r--r-- | app/tasks/importtasks.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py index 1950d5b..7940a17 100644 --- a/app/tasks/importtasks.py +++ b/app/tasks/importtasks.py @@ -30,6 +30,12 @@ class GithubURLMaker: def isValid(self): return self.baseUrl is not None + def getRepoURL(self): + return "https://github.com/" + self.user + "/" + self.repo + ".git" + + def getIssueTrackerURL(self): + return "https://github.com/" + self.user + "/" + self.repo + "/issues/" + def getModConfURL(self): return self.baseUrl + "/mod.conf" @@ -70,10 +76,11 @@ def getMeta(urlstr): if not urlmaker.isValid(): raise TaskError("Error! Url maker not valid") - print(urlmaker.getModConfURL()) - result = {} + result["repo"] = urlmaker.getRepoURL() + result["issueTracker"] = urlmaker.getIssueTrackerURL() + try: contents = urllib.request.urlopen(urlmaker.getModConfURL()).read().decode("utf-8") conf = parseConf(contents) @@ -82,11 +89,12 @@ def getMeta(urlstr): result[key] = conf[key] except KeyError: pass - - print(conf) except OSError: print("mod.conf does not exist") + if "name" in result: + result["title"] = result["name"].replace("_", " ").title() + if not "description" in result: try: contents = urllib.request.urlopen(urlmaker.getDescURL()).read().decode("utf-8") @@ -94,6 +102,12 @@ def getMeta(urlstr): except OSError: print("description.txt does not exist!") + if "description" in result: + desc = result["description"] + idx = desc.find(".") + 1 + cutIdx = min(len(desc), 200 if idx < 5 else idx) + result["short_description"] = desc[:cutIdx] + return result @celery.task() |