aboutsummaryrefslogtreecommitdiff
path: root/app/tasks/importtasks.py
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2018-06-05 19:59:07 +0100
committerrubenwardy <rw@rubenwardy.com>2018-06-05 19:59:07 +0100
commit99b21f996cde01446b13f4c7ec525e5a6bf3df1e (patch)
treed65ec1528cfb778160792b46b5b380f19811bb9d /app/tasks/importtasks.py
parent700cd7ce1f0e06ab23f266f5ab973a17e71de8ee (diff)
downloadcheatdb-99b21f996cde01446b13f4c7ec525e5a6bf3df1e.tar.xz
Fix screenshot import being broken
Diffstat (limited to 'app/tasks/importtasks.py')
-rw-r--r--app/tasks/importtasks.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/tasks/importtasks.py b/app/tasks/importtasks.py
index c2460d2..2d8ee8b 100644
--- a/app/tasks/importtasks.py
+++ b/app/tasks/importtasks.py
@@ -26,6 +26,39 @@ from app.models import *
from app.tasks import celery, TaskError
from app.utils import randomString
+
+class GithubURLMaker:
+ def __init__(self, url):
+ # Rewrite path
+ import re
+ m = re.search("^\/([^\/]+)\/([^\/]+)\/?$", url.path)
+ if m is None:
+ return
+
+ user = m.group(1)
+ repo = m.group(2).replace(".git", "")
+ self.baseUrl = "https://raw.githubusercontent.com/{}/{}/master" \
+ .format(user, repo)
+ self.user = user
+ self.repo = repo
+
+ def isValid(self):
+ return self.baseUrl is not None
+
+ def getRepoURL(self):
+ return "https://github.com/{}/{}".format(self.user, self.repo)
+
+ def getScreenshotURL(self):
+ return self.baseUrl + "/screenshot.png"
+
+ def getCommitsURL(self, branch):
+ return "https://api.github.com/repos/{}/{}/commits?sha={}" \
+ .format(self.user, self.repo, urllib.parse.quote_plus(branch))
+
+ def getCommitDownload(self, commit):
+ return "https://github.com/{}/{}/archive/{}.zip" \
+ .format(self.user, self.repo, commit)
+
krock_list_cache = None
krock_list_cache_by_name = None
def getKrockList():