This repository was archived by the owner on Sep 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathget_stargazers.py
More file actions
51 lines (43 loc) · 1.48 KB
/
Copy pathget_stargazers.py
File metadata and controls
51 lines (43 loc) · 1.48 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#
# Copyright 2021- IBM Inc. All rights reserved
# SPDX-License-Identifier: Apache2.0
#
import sys
import utils.github_utils as gh
from utils.cloudant_utils import cloudant_db as db, save_doc
def main(args):
try:
limit = int(args[0])
except:
limit = 1000
try:
skip = int(args[1])
except:
skip = 0
try:
sort = "asc" if args[2]=="asc" else "desc"
except:
sort = "desc"
repos = [ r for r in db.get_query_result({
"type":"Repo",
"stargazers_events": { "$exists": False },
"stars": { "$gt": 0 }
},["_id", "stars"], limit=limit, skip=skip, raw_result=True, sort=[{'stars': sort}] )["docs"] ]
print("repos", len(repos))
for repo in repos:
print("\n", repo)
repo_id = repo["_id"]
try:
starred_events = gh.get_starred_events(repo_id, "2019-01-01")
starred_events = [] if starred_events is None else starred_events
save_doc(repo_id+"/stargazers", {"type": "RepoStargazers", "repo_id": repo_id, "events": starred_events })
save_doc(repo_id, {
"starred_events": None,
"stargazers_events_id": repo_id+"/stargazers",
"stargazers_events": len(starred_events),
"stars": gh.get_repo_by_fullname(repo_id).stargazers_count })
except Exception as e:
print(str(e))
pass
if __name__ == "__main__":
main(sys.argv[1:])