forked from gnip/support
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddRule.py
More file actions
executable file
·36 lines (26 loc) · 850 Bytes
/
AddRule.py
File metadata and controls
executable file
·36 lines (26 loc) · 850 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
#!/usr/bin/env python
import urllib2
import base64
import json
import xml
import sys
def post():
# Expected Premium Stream URL Format:
# https://api.gnip.com:443/accounts/<account>/publishers/<publisher>/streams/<stream>/<label>/rules.json
url = 'ENTER_RULES_API_URL_HERE'
UN = 'ENTER_USERNAME_HERE'
PWD = 'ENTER_PASSWORD_HERE'
rule = 'testRule'
tag = 'testTag'
values = '{"rules": [{"value":"' + rule + '","tag":"' + tag + '"}]}'
base64string = base64.encodestring('%s:%s' % (UN, PWD)).replace('\n', '')
req = urllib2.Request(url=url, data=values)
req.add_header('Content-type', 'application/json')
req.add_header("Authorization", "Basic %s" % base64string)
try:
response = urllib2.urlopen(req)
except urllib2.HTTPError as e:
print e.read()
the_page = response.read()
if __name__ == "__main__":
post()