Last active
October 24, 2019 06:17
-
-
Save hhatto/5f5cdac4d5f65ae9774e5fa76267bc85 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result