-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbulk.py
More file actions
121 lines (85 loc) · 2.98 KB
/
bulk.py
File metadata and controls
121 lines (85 loc) · 2.98 KB
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
import csv
from math import floor
import requests as r
import time
from random import random
key = "5a690b08d33a4f7e998565a0510b0e53"
file = 'links.csv'
def unordered_bulk_abbrefy(file, key):
try:
with open(file) as f:
reader = csv.reader(f, delimiter=',')
line = 0
for row in reader:
if line == 0:
line += 1
pass
else:
url = 'https://abbrefy.xyz/api/v1/url/abbrefy/'
h = {
"apiKey": key
}
b = {
"url": row[0]
}
resp = r.post(url=url, json=b, headers=h)
res = resp.json()
if len(row) > 1 and row[1]:
url = 'https://abbrefy.xyz/api/v1/url/update/'
h = {
"apiKey": key
}
b = {
"slug": row[1],
"idSlug": res['slug'],
}
respo = r.put(url=url, json=b, headers=h)
res = respo.json()
return True
except:
return False
def ordered_bulk_abbrefy(file):
key = 'd08604dafe2e4da988c6eb8818dce872'
i = len(key)
location = f'{key[int(random() * i):int(random() * i)]}{floor(time.time() * 1000)}.csv'
with open(file) as f:
reader = csv.reader(f, delimiter=',')
line = 0
for row in reader:
if line == 0:
line += 1
pass
else:
url = 'https://abbrefy.xyz/api/v1/url/abbrefy/'
h = {
"apiKey": key
}
b = {
"url": row[0]
}
resp = r.post(url=url, json=b, headers=h)
res = resp.json()
initial = res['url']
if len(row) > 1 and row[1]:
url = 'https://abbrefy.xyz/api/v1/url/update/'
h = {
"apiKey": key
}
b = {
"slug": row[1],
"idSlug": res['slug'],
}
respo = r.put(url=url, json=b, headers=h)
res = respo.json()
with open(location, 'a') as l:
if 'url' in res:
l.write(res['url'] + '\n')
l.close()
elif 'data' in res and 'url' in res['data']:
l.write(res['data']['url'] + '\n')
l.close()
else:
l.write(res['error'] +
' --- USED INSTEAD --- ' + initial + '\n')
l.close()
return True, location