Add Krock's mod search to meta importer to find forum topic ID

This commit is contained in:
rubenwardy 2018-05-12 18:50:09 +01:00
parent db3d63d91a
commit 38ed03f49a
No known key found for this signature in database
GPG Key ID: A1E29D52FF81513C
3 changed files with 68 additions and 3 deletions

View File

@ -24,13 +24,15 @@ $(function() {
$(".pkg_repo").hide()
performTask("/tasks/getmeta/new/?url=" + encodeURI(repoURL)).then(function(result) {
console.log(result)
$("#name").val(result.name || "")
$("#title").val(result.title || "")
$("#repo").val(result.repo || repoURL)
$("#issueTracker").val(result.issueTracker || "")
$("#desc").val(result.description || "")
$("#shortDesc").val(result.short_description || "")
if (result.forumId) {
$("#forums").val(result.forumId)
}
finish()
}).catch(function(e) {
alert(e)

View File

@ -52,6 +52,62 @@ class GithubURLMaker:
return "https://github.com/" + self.user + "/" + self.repo + "/archive/" + commit + ".zip"
krock_list_cache = None
krock_list_cache_by_name = None
def getKrockList():
global krock_list_cache
global krock_list_cache_by_name
if krock_list_cache is None:
contents = urllib.request.urlopen("http://krock-works.16mb.com/MTstuff/modList.php").read().decode("utf-8")
list = json.loads(contents)
def h(x):
if not ("title" in x and "author" in x and \
"topicId" in x and "link" in x and x["link"] != ""):
return False
import re
m = re.search("\[([A-Za-z0-9_]+)\]", x["title"])
if m is None:
return False
x["name"] = m.group(1)
return True
def g(x):
return {
"title": x["title"],
"author": x["author"],
"name": x["name"],
"topicId": x["topicId"],
"link": x["link"],
}
krock_list_cache = [g(x) for x in list if h(x)]
krock_list_cache_by_name = {}
for x in krock_list_cache:
if not x["name"] in krock_list_cache_by_name:
krock_list_cache_by_name[x["name"]] = []
krock_list_cache_by_name[x["name"]].append(x)
return krock_list_cache, krock_list_cache_by_name
def findModInfo(author, name, link):
_, lookup = getKrockList()
if name in lookup:
if len(lookup[name]) == 1:
return lookup[name][0]
for x in lookup[name]:
if x["author"] == author:
return x
return None
def parseConf(string):
retval = {}
for line in string.split("\n"):
@ -63,8 +119,9 @@ def parseConf(string):
return retval
@celery.task()
def getMeta(urlstr):
def getMeta(urlstr, author):
url = urlparse(urlstr)
urlmaker = None
@ -108,6 +165,10 @@ def getMeta(urlstr):
cutIdx = min(len(desc), 200 if idx < 5 else idx)
result["short_description"] = desc[:cutIdx]
info = findModInfo(author, result["name"], result["repo"])
if info is not None:
result["forumId"] = info["topicId"]
return result
@celery.task()

View File

@ -13,7 +13,9 @@ from .utils import *
@app.route("/tasks/getmeta/new/", methods=["POST"])
@login_required
def new_getmeta_page():
aresult = getMeta.delay(request.args.get("url"))
author = request.args.get("author")
author = current_user.forums_username if author is None else author
aresult = getMeta.delay(request.args.get("url"), author)
return jsonify({
"poll_url": url_for("check_task", id=aresult.id),
})