Last active
February 9, 2016 21:45
-
-
Save kbknapp/380e245ca58a4f44ad74 to your computer and use it in GitHub Desktop.
gets simple project stats
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
#!/usr/bin/python3 | |
import subprocess | |
import os | |
import os.path | |
import sys | |
crates_io_lic = '[![Crates.io License](https://img.shields.io/crates/l/{}.svg)]({})' | |
crates_io_dl = '[![Crates.io Downloads](https://img.shields.io/crates/d/{}.svg)]({})' | |
github_stars = '[![GitHub stars](https://img.shields.io/github/stars/{}/{}.svg?style=social&label=Stars)]({})' | |
github_lic = '[![Github License](https://img.shields.io/github/license/{}/{}.svg)]({})' | |
urls = [ | |
"https://github.com/kbknapp/clap-rs", | |
"https://github.com/kbknapp/cargo-count", | |
"https://github.com/kbknapp/cargo-outdated", | |
"https://github.com/kbknapp/cargo-graph", | |
"https://github.com/kbknapp/docli-rs", | |
"https://github.com/kbknapp/doapi-rs", | |
"https://github.com/Manishearth/rust-clippy", | |
"https://github.com/dpc/mioco", | |
"https://github.com/dpc/rhex", | |
"https://github.com/AtheMathmo/rusty-machine", | |
"https://github.com/swiboe/swiboe", | |
] | |
class Project: | |
def __init__(self, url): | |
self.url = url | |
self.repo = url.split('/')[-1] | |
self.user = url.split('/')[-2] | |
subprocess.run(['git clone {}'.format(url)], shell=True) | |
os.chdir('{}'.format(self.repo)) | |
print('Counting commits...') | |
proc = subprocess.run(['git rev-list --all --count'], shell=True, check=True, stdout=subprocess.PIPE) | |
self.commits = proc.stdout.strip().decode('utf-8') | |
print('Looking for name...') | |
try: | |
with open('Cargo.toml', 'r') as f: | |
for line in f: | |
line = line.strip() | |
if line.startswith('name'): | |
withq = line.split('=')[-1] | |
withq = withq.strip() | |
self.crate = withq[1:-1] | |
break | |
self.clic = crates_io_lic.format(self.crate, self.url) | |
self.dls = crates_io_dl.format(self.crate, self.url) | |
except: | |
self.crate = '' | |
self.clic = '' | |
self.dls = '' | |
self.stars = github_stars.format(self.user, self.repo, self.url) | |
self.glic = github_lic.format(self.user, self.repo, self.url) | |
print('Cleaning up...') | |
os.chdir('..') | |
def __str__(self): | |
return " * [{}/{}]({}) **{}** commits in total {} {} {} {}".format(self.user, self.repo, self.url, self.commits, self.stars, self.dls, self.clic, self.glic) | |
def main(): | |
projs = [Project(u) for u in urls] | |
with open('projects.md', 'w+') as f: | |
f.write('### Project Stats\n\n') | |
for p in projs: | |
f.write(p.__str__() + '\n') | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment