Skip to content

Instantly share code, notes, and snippets.

@hhatto
Last active October 24, 2019 06:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hhatto/5f5cdac4d5f65ae9774e5fa76267bc85 to your computer and use it in GitHub Desktop.
Save hhatto/5f5cdac4d5f65ae9774e5fa76267bc85 to your computer and use it in GitHub Desktop.
import time
import re
import requests
PAGE_SIZE = 100
SLEEP_TIME = 60 # sec
BASE_URL = "https://api.github.com/search/repositories?q=rust+language:rust&sort=stars&order=desc&per_page=100&page=%d"
RE_PREFIX_RS_AND_DASH = re.compile("^rs-")
RE_PREFIX_RS_AND_DOT = re.compile("^rs\.")
RE_SUFFIX_RS_AND_DASH = re.compile("-rs$")
RE_SUFFIX_RS_AND_DOT = re.compile("\.rs$")
RE_PREFIX_RUST_AND_DASH = re.compile("^rust-")
RE_PREFIX_RUST_AND_DOT = re.compile("^rust\.")
RE_SUFFIX_RUST_AND_DASH = re.compile("-rust$")
RE_SUFFIX_RUST_AND_DOT = re.compile("\.rust$")
RE_PREFIX_RS = re.compile("^rs")
RE_PREFIX_RUST = re.compile("^rust")
RE_SUFFIX_RS = re.compile("rs$")
RE_SUFFIX_RUST = re.compile("rust$")
REPO_NAME_STATS = {
"prefix_rs_dash": 0,
"prefix_rs_dot": 0,
"suffix_rs_dash": 0,
"suffix_rs_dot": 0,
"prefix_rust_dash": 0,
"prefix_rust_dot": 0,
"suffix_rust_dash": 0,
"suffix_rust_dot": 0,
"prefix_rs": 0,
"prefix_rust": 0,
"suffix_rs": 0,
"suffix_rust": 0,
"none": 0,
}
def check_and_stats_reponame(name):
# prefix
if RE_PREFIX_RS_AND_DASH.search(name):
REPO_NAME_STATS['prefix_rs_dash'] += 1
elif RE_PREFIX_RS_AND_DOT.search(name):
REPO_NAME_STATS['prefix_rs_dot'] += 1
elif RE_PREFIX_RUST_AND_DASH.search(name):
REPO_NAME_STATS['prefix_rust_dash'] += 1
elif RE_PREFIX_RUST_AND_DOT.search(name):
REPO_NAME_STATS['prefix_rust_dot'] += 1
elif RE_PREFIX_RS.search(name):
REPO_NAME_STATS['prefix_rs'] += 1
elif RE_PREFIX_RUST.search(name):
REPO_NAME_STATS['prefix_rust'] += 1
# suffix
elif RE_SUFFIX_RS_AND_DASH.search(name):
REPO_NAME_STATS['suffix_rs_dash'] += 1
elif RE_SUFFIX_RS_AND_DOT.search(name):
REPO_NAME_STATS['suffix_rs_dot'] += 1
elif RE_SUFFIX_RUST_AND_DASH.search(name):
REPO_NAME_STATS['suffix_rust_dash'] += 1
elif RE_SUFFIX_RUST_AND_DOT.search(name):
REPO_NAME_STATS['suffix_rust_dot'] += 1
elif RE_SUFFIX_RS.search(name):
REPO_NAME_STATS['suffix_rs'] += 1
elif RE_SUFFIX_RUST.search(name):
REPO_NAME_STATS['suffix_rust'] += 1
# none
else:
REPO_NAME_STATS['none'] += 1
def main():
is_first = True
for page in range(1, 11):
res = requests.get(BASE_URL % page)
if res.status_code != 200:
break
if page == 0:
total_repos = int(res.json()["total_count"])
print("total rust repos: %d" % total_repos)
# print("rate-limit: %s/%s" % (res.headers['X-RateLimit-Remaining'], res.headers['X-RateLimit-Limit']))
datas = res.json()["items"]
for d in datas:
print("name=%s, full_name=%s, score=%s, star=%s" % (d['name'], d['full_name'], d['score'], d['stargazers_count']))
check_and_stats_reponame(d['name'])
star = int(d['stargazers_count'])
time.sleep(SLEEP_TIME)
print(REPO_NAME_STATS)
def test():
check_and_stats_reponame("rs-hoge")
assert(REPO_NAME_STATS["prefix_rs_dash"] == 1)
check_and_stats_reponame("rs.hoge")
assert(REPO_NAME_STATS["prefix_rs_dot"] == 1)
check_and_stats_reponame("rust-hoge")
assert(REPO_NAME_STATS["prefix_rust_dash"] == 1)
check_and_stats_reponame("rust.hoge")
assert(REPO_NAME_STATS["prefix_rust_dot"] == 1)
check_and_stats_reponame("rusthoge")
assert(REPO_NAME_STATS["prefix_rust"] == 1)
check_and_stats_reponame("rshoge")
assert(REPO_NAME_STATS["prefix_rs"] == 1)
check_and_stats_reponame("hoge-rs")
assert(REPO_NAME_STATS["suffix_rs_dash"] == 1)
check_and_stats_reponame("hoge.rs")
assert(REPO_NAME_STATS["suffix_rs_dot"] == 1)
check_and_stats_reponame("hoge-rust")
assert(REPO_NAME_STATS["suffix_rust_dash"] == 1)
check_and_stats_reponame("hoge.rust")
assert(REPO_NAME_STATS["suffix_rust_dot"] == 1)
check_and_stats_reponame("hogers")
assert(REPO_NAME_STATS["suffix_rs"] == 1)
check_and_stats_reponame("hogerust")
assert(REPO_NAME_STATS["suffix_rust"] == 1)
assert(REPO_NAME_STATS["none"] == 0)
check_and_stats_reponame("iron")
assert(REPO_NAME_STATS["none"] == 1)
if __name__ == '__main__':
# test()
main()
@hhatto
Copy link
Author

hhatto commented Jun 20, 2016

name=rust-picotcp, full_name=maximevince/rust-picotcp, score=7.417333, star=10
name=rust-emojicons, full_name=jiri/rust-emojicons, score=7.417333, star=10
name=rust-prolog, full_name=dagit/rust-prolog, score=7.391178, star=10
name=htmlstream-rust, full_name=leizongmin/htmlstream-rust, score=7.391178, star=10
name=rust-raytrace, full_name=jorendorff/rust-raytrace, score=7.3887463, star=10
name=pcp, full_name=ptal/pcp, score=6.524393, star=10
name=ctest, full_name=alexcrichton/ctest, score=6.5188074, star=10
name=oauth2-rs, full_name=alexcrichton/oauth2-rs, score=6.485675, star=10
{'suffix_rust': 11, 'none': 429, 'suffix_rs_dot': 33, 'suffix_rust_dot': 1, 'suffix_rs_dash': 114, 'prefix_rust_dot': 2, 'suffix_rust_dash': 39, 'prefix_rust': 79, 'prefix_rs_dash': 5, 'suffix_rs': 11, 'prefix_rs': 6, 'prefix_rust_dash': 270, 'prefix_rs_dot': 0}

result

'none': 429,                # hoge
'prefix_rust_dash': 270,    # rust-hoge
'suffix_rs_dash': 114,      # hoge-rs
'prefix_rust': 79,          # rusthoge
'suffix_rust_dash': 39,     # hoge-rust
'suffix_rs_dot': 33,        # hoge.rs
'suffix_rs': 11,            # hogers
'suffix_rust': 11,          # hogerust
'prefix_rs': 6,             # rshoge
'prefix_rs_dash': 5,        # rs-hoge
'prefix_rust_dot': 2,       # rust.hoge
'suffix_rust_dot': 1,       # hoge.rust
'prefix_rs_dot': 0          # rs.hoge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment