2018-04-03 16:42:26 +02:00
|
|
|
import requests
|
|
|
|
import json
|
|
|
|
import datetime
|
|
|
|
import os
|
2023-06-11 14:34:22 +02:00
|
|
|
import toml
|
2018-04-03 16:42:26 +02:00
|
|
|
|
2018-05-30 02:31:45 +02:00
|
|
|
from .. import db
|
2018-04-03 16:42:26 +02:00
|
|
|
|
2018-05-30 02:31:45 +02:00
|
|
|
class UnlistedApp(db.Model):
|
2018-04-03 16:42:26 +02:00
|
|
|
|
2018-05-30 02:31:45 +02:00
|
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
|
|
url = db.Column(db.String(100), unique=True, nullable=False)
|
|
|
|
name = db.Column(db.String(64), nullable=False)
|
|
|
|
owner = db.Column(db.String(64), nullable=False)
|
|
|
|
description = db.Column(db.String(256))
|
|
|
|
updated_days_ago = db.Column(db.Integer, default=-1)
|
|
|
|
|
|
|
|
def __repr__(self):
|
|
|
|
return '<UnlistedApp %r>' % self.name
|
|
|
|
|
|
|
|
def init():
|
|
|
|
pass
|
|
|
|
|
|
|
|
def update():
|
|
|
|
|
|
|
|
UnlistedApp.query.delete()
|
2018-04-03 16:42:26 +02:00
|
|
|
|
2023-06-11 14:34:22 +02:00
|
|
|
community = toml.loads(requests.get("https://raw.githubusercontent.com/YunoHost/apps/master/apps.toml").text)
|
2018-04-03 16:42:26 +02:00
|
|
|
|
2018-05-30 02:31:45 +02:00
|
|
|
known_apps = set()
|
2019-04-16 17:26:36 +02:00
|
|
|
known_apps = known_apps.union([os.path.basename(app["url"]).lower() for app in community.values() ])
|
2018-04-03 16:42:26 +02:00
|
|
|
|
|
|
|
apps = []
|
|
|
|
|
2019-04-16 17:26:36 +02:00
|
|
|
for i in range(1,8):
|
2018-04-03 16:42:26 +02:00
|
|
|
|
|
|
|
print("Page " + str(i) + " ... ")
|
|
|
|
r = requests.get("https://api.github.com/search/repositories?q=_ynh&sort=updated&per_page=100&page="+str(i))
|
2018-05-30 02:31:45 +02:00
|
|
|
assert r.status_code == 200, r.text
|
2018-04-03 16:42:26 +02:00
|
|
|
j = json.loads(r.text)
|
|
|
|
print(str(len(j["items"])) + " items ")
|
|
|
|
for item in j["items"]:
|
|
|
|
|
|
|
|
if str(item["size"]) == "0":
|
|
|
|
continue
|
|
|
|
|
2018-05-30 02:31:45 +02:00
|
|
|
if not item["name"].endswith("_ynh"):
|
2018-04-03 16:42:26 +02:00
|
|
|
continue
|
|
|
|
|
2019-04-16 17:26:36 +02:00
|
|
|
if item["name"].lower() in known_apps:
|
2018-04-03 16:42:26 +02:00
|
|
|
continue
|
|
|
|
|
2019-03-06 01:44:23 +01:00
|
|
|
owner = item["owner"]["login"]
|
|
|
|
|
|
|
|
r = requests.head("https://raw.githubusercontent.com/%s/%s/master/manifest.json" % (owner, item["name"]))
|
|
|
|
if r.status_code != 200:
|
|
|
|
continue
|
|
|
|
r = requests.head("https://raw.githubusercontent.com/%s/%s/master/scripts/install" % (owner, item["name"]))
|
|
|
|
if r.status_code != 200:
|
|
|
|
continue
|
|
|
|
|
2018-05-30 02:31:45 +02:00
|
|
|
item["name"] = item["name"].replace("_ynh", "")
|
2018-04-03 16:42:26 +02:00
|
|
|
|
2018-05-30 02:31:45 +02:00
|
|
|
app = UnlistedApp(name=item["name"],
|
|
|
|
url=item["html_url"],
|
|
|
|
owner=item["owner"]["login"],
|
|
|
|
description=item["description"],
|
2019-03-06 01:44:23 +01:00
|
|
|
updated_days_ago=githubDateToDaysAgo(item["pushed_at"])
|
2018-05-30 02:31:45 +02:00
|
|
|
)
|
|
|
|
db.session.add(app)
|
2018-04-03 16:42:26 +02:00
|
|
|
|
2018-05-30 02:31:45 +02:00
|
|
|
db.session.commit()
|
2018-04-03 16:42:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
def githubDateToDaysAgo(date):
|
|
|
|
now = datetime.datetime.now()
|
|
|
|
date = datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%SZ")
|
|
|
|
return (now - date).days
|
|
|
|
|