-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
44 lines (37 loc) · 1.41 KB
/
utils.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
import tweepy
from datetime import datetime
from pytz import timezone
from config import *
# Authenticate to Twitter
twitter_auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
twitter_auth.set_access_token(TWITTER_ACCESS_KEY, TWITTER_ACCESS_SECRET)
twitter_api = tweepy.API(twitter_auth)
# Util functions
def log(level, msg):
print("[" + str(datetime.now()) + "] [" + level + "] " + msg)
def str_to_datetime(str):
return datetime.fromisoformat(str[:-1]).replace(tzinfo=timezone('UTC')).astimezone(timezone('US/Eastern'))
def generate_request_js(url):
script = '''
function httpGet(theUrl)
{
let xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
return xmlhttp.responseText;
}
}
xmlhttp.open("GET", theUrl, false);
xmlhttp.setRequestHeader("accept", "application/json, text/plain, */*");
xmlhttp.setRequestHeader("authorization", "Bearer ''' + CAPTCHA_KEY + '''");
xmlhttp.send();
return xmlhttp.response;
}
return httpGet("''' + url + '''");
'''
return script