forked from DragSama/DragSama
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_fav.py
More file actions
37 lines (32 loc) · 861 Bytes
/
update_fav.py
File metadata and controls
37 lines (32 loc) · 861 Bytes
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
import requests
import re
query = """
query($query: String){
User(name: $query){
favourites{
anime {
nodes{
siteUrl
title {
romaji
english
}
}
}
}
}
}
"""
regex = re.compile("<!-- anime_list_start-->.*<!-- anime_list_end-->", re.DOTALL)
def update_readme():
vars = {"query": 'DragSama'}
req = requests.post('https://graphql.anilist.co', json={'query': query, 'variables': vars}).json()['data']['User']['favourites']['anime']['nodes']
new = '<!-- anime_list_start-->\n'
for x in req:
new += f"* [{x['title']['english']}]({x['siteUrl']}) - ({x['title']['romaji']})\n"
new += "<!-- anime_list_end-->"
with open('README.md', 'r') as f:
text = regex.sub(new, f.read())
with open('README.md', 'w') as w:
w.write(text)
update_readme()