-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
145 lines (128 loc) · 3.86 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import requests
import json
import feedparser
import textdistance as td
import transmissionrpc
from datetime import datetime
import config
today = datetime.today().strftime("%d/%m/%Y %H:%M")
url = 'https://graphql.anilist.co'
#TODO pozbyć się tego
media_id = []
id_list = []
title_list = []
magnet_list = []
log_list = []
acc_list = []
match_list = []
query = '''
query ($id: String, $page: Int) { # Define which variables will be used in the query (id)
Page (perPage: 50, page: $page) {
mediaList (userName: $id, status: PLANNING, type: ANIME) {
mediaId
}
}
}
'''
for n in range(10):
variables = {
'id': config.anilist_username,
'page': n,
}
# Make the HTTP Api request
response = requests.post(url, json={'query': query, 'variables': variables})
json_obj = json.loads(response.text)["data"]["Page"]["mediaList"]
if not json_obj:
break
for mediaid in json_obj:
media_id.append(mediaid)
query = '''
query ($id: String, $page: Int) { # Define which variables will be used in the query (id)
Page (perPage: 50, page: $page) {
mediaList (userName: $id, status: CURRENT, type: ANIME) {
mediaId
}
}
}
'''
for n in range(10):
variables = {
'id': config.anilist_username,
'page': n,
}
# Make the HTTP Api request
response = requests.post(url, json={'query': query, 'variables': variables})
json_obj = json.loads(response.text)["data"]["Page"]["mediaList"]
if not json_obj:
break
for mediaid in json_obj:
media_id.append(mediaid)
for dict in media_id:
id_list.append(dict['mediaId'])
media_id = id_list
media_id = list(dict.fromkeys(media_id))
#print(len(media_id), media_id)
for anime in media_id:
query = '''
query ($id: Int) {
Media (id: $id) {
title {
romaji
}
}
}
'''
variables = {
'id': anime
}
response = requests.post(url, json={'query': query, 'variables': variables})
json_obj = json.loads(response.text)["data"]["Media"]["title"]["romaji"]
title_list.append(json_obj)
#print(title_list)
try:
f = open("id.txt", "r")
except FileNotFoundError:
f = open("id.txt", "w+")
last_id = f.readline()
f.close()
#rrs = 'https://horriblesubs.info/rss.php?res=1080'
rrs = 'http://nyaa.si/?page=rss&q=[HorribleSubs]+[1080p]'
feed = feedparser.parse(rrs)
for post in feed['entries']:
if post['id'] == last_id:
break
best_acc = 0
best_match = ''
for anime in title_list:
acc = td.jaro.similarity(post['title'][15:-17].lower(), anime.lower())
# acc = td.sorensen.normalized_similarity(post['title'][15:-17], anime)
# acc = td.jaccard.normalized_similarity(post['title'][15:-17], anime)
if acc > best_acc:
best_acc = acc
best_match = anime
if best_acc > 0.75:
print(best_acc, best_match, "==============", post['title'][15:-17])
magnet_list.append(post['link'])
log_list.append(post['title'])
acc_list.append(best_acc)
match_list.append(best_match)
f = open("id.txt", "w+")
f.write(feed['entries'][0]['id'])
f.close()
try:
tc = transmissionrpc.Client(config.transmission_ip, port=config.transmission_ip)
for link in magnet_list:
temp_log = log_list[magnet_list.index(link)][15:-17]
tc.add_torrent(link, download_dir='/usr/local/etc/transmission/home/Downloads/' + temp_log)
except:
print("Time out Error")
if len(magnet_list) > 0:
print("Successfully added ", len(magnet_list), " Torrents")
else:
print("No Torrents added")
f = open("downloaded_anime.log", "a+")
n = 0
for log in log_list:
f.write("[" + str(today) + "] " + log + " Best match is: " + match_list[n] + " with " + str(acc_list[n] * 100)[:5] + "% Accuracy" + "\n")
n += 1
f.close()