-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredirect.py
executable file
·46 lines (39 loc) · 1.21 KB
/
redirect.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
#!/usr/local/bin/python
import requests
import json
f = open('.credentials', 'r')
auth = f.read().rstrip('\n').split(' ')
auth = (auth[0], auth[1])
session = requests.Session()
def add_redirect(origin, target, code):
url = "http://api.cratejoy.com/v1/page_redirects/"
response = requests.post(url, data=json.dumps({\
'path': origin,\
'target': target,\
'enabled': True,\
'code': code\
}), auth=auth)
print response.content
def disable_redirect(id):
url = "http://api.cratejoy.com/v1/page_redirects/{}/".format(id)
print url
response = requests.put(url, data=json.dumps({\
'enabled': False,\
}), auth=auth)
print response.content
def enable_redirect(id):
url = "http://api.cratejoy.com/v1/page_redirects/{}/".format(id)
print url
response = requests.put(url, data=json.dumps({\
'enabled': True,\
}), auth=auth)
print response.content
def show_redirects():
url = "http://api.cratejoy.com/v1/page_redirects/"
print url
response = requests.get(url, auth=auth)
print response.content
#add_redirect('/wrongplacetobe', '/placetobe', 302)
#show_redirects()
#disable_redirect(138398113)
#enable_redirect(138398113)