-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgithub2bibtex.py
executable file
·54 lines (47 loc) · 1.09 KB
/
github2bibtex.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!python3
template="""
@misc{_id_
author={_author_},
title={_title_},
year={2023},
url={_url_},
}
"""
template="""@misc{{{}
author={},
title={},
year={},
url={},
}}"""
year=2023
def repo2bib(identifier:str):
info = identifier[:-1].split('/')
author=info[-2]
title=info[-1]
# print("author:{}, title:{}".format(author,title))
id="{}{}{}".format(author, year, title)
url="https://github.com/{}/{}".format(author,title)
return template.format(id, author, title, year, url)
def main():
filename = 'repos.txt'
bibs=[]
with open(filename, 'r') as f:
repos = f.readlines()
# print(repos)
for repo in repos:
# print(repo)
bibs.append(repo2bib(repo))
filename= 'repos.bib'
with open(filename,'w') as f:
for b in bibs:
print(b)
f.write(b+'\n')
print('The outputs have been wrote into {}'.format(filename))
import sys
if __name__=="__main__":
if len(sys.argv) > 1:
print(sys.argv)
repo=sys.argv[-1]
print(repo2bib(repo))
else:
main()