-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
33 lines (22 loc) · 1.04 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from spin_http import Request, Response, http_send
from spin_config import config_get
from spin_key_value import kv_open_default
from datetime import date
import json
def handle_request(request):
gh_auth_token = config_get("gh_auth_token")
owner=config_get("owner")
repo=config_get("repo")
print("https://api.github.com/repos/"+owner+"/"+repo)
response = http_send(
Request("GET", "https://api.github.com/repos/"+owner+"/"+repo,
{"authorization": 'Bearer '+ gh_auth_token, "User-agent": "curl/7.88.1"}, None))
repo_stats = json.loads(str(response.body, 'utf-8'))
num_stargazers = repo_stats["stargazers_count"]
store = kv_open_default()
print("Num of stargazers: "+str(num_stargazers))
print("Date: " + (str(date.today())))
store.set(str(date.today()), bytes(str(num_stargazers),"utf-8"))
return Response(200,
{"content-type": "text/plain"},
bytes(f"Here is the stargazer count for the " + str(repo) + " repo today ("+str(date.today())+"): "+str(num_stargazers), "utf-8"))