-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
172 lines (163 loc) · 4.81 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
'''Contains general functions used by more than one script. Also contains
global vars'''
import sqlite3
import os
import json
import requests
__init__ = ['DATABASES', 'get_database_connection', 'TEST_PARAMS', 'URLS',
'VERBOSE', 'create_table', 'get_ticker']
URLS = {'COMPANY_NAME_TO_TICKER_API': 'http://chstocksearch.herokuapp.com/api/',
'TWITTER_SEARCH_URL': 'https://twitter.com/search?q='}
VERBOSE = False
TEST_PARAMS = {'ANALYSER_COMPANY': 'starbucks',
'MAX_TWEETS' : 1100 }
COMPANIES = {
"Apple" :
"Apple OR "
+"#Apple OR "
+"iPad OR "
+"iphone OR "
+"iPod OR "
+"apple watch OR "
+"mac OR "
+"macbook OR "
+"iMac"
,
"Facebook" :
"Facebook OR "
+"#Facebook OR "
+"news feed OR "
+"poke OR "
+"status OR "
+"timeline OR "
+"messenger"
,
"Costa" :
'Costa OR '
+'#Costa OR '
+'Whitbread '
,
"Microsoft" :
'Mircosoft OR '
+'#Mircosoft OR '
+'Surface OR '
+'power point OR '
+'excel OR '
+'vista OR '
+'kinect OR '
+'bing OR '
+'visual basic OR '
+'visual studio OR '
+'ms-dos'
,
"Astrazeneca" :
"Astrazeneca OR "
+"ARIMIDEX OR "
+"ATACAND OR "
+"NEXIUM OR "
+"ONGLYZA OR "
+"PLENDIL OR "
+"PRILOSEC OR "
+"PULMICORT OR "
+"RHINOCORT OR "
+"CRESTOR OR "
+"DALIRESP OR "
+"SYMBICORT OR "
+"SYNAGIS OR "
+"TAGRISSO OR "
+"FASLODEX OR "
+"Kombiglyze OR "
+"Farxiga OR "
+"Astrazeneca OR "
+"Astrazeneca OR "
+"Astrazeneca OR "
# +"Carbocaine OR "
# +"Citanes OR "
# +"Diprivan OR "
# +"EMLA OR "
# +"MarcaineOR "
# +"Naropin OR "
# +"Xylocaine OR "
# +"Xyloproct OR "
# +"Atacand OR "
# +"Betaloc OR "
# +"BrilintaOR "
# +"Crestor OR "
# +"ExantaOR "
# +"Epanova OR "
# +"Imdur OR "
# +"Inderal OR "
# +"Lexxel OR "
# +"Logimax OR "
# +"Nif-Ten OR "
# +"Plendil OR "
# +"Ramace OR "
# +"SelokenOR "
# +"Tenoretic OR "
# +"Tenormin OR "
# +"Unimax OR "
# +"Zestoretic OR "
# +"Zestril OR "
# +"Bydureon OR "
# +"Byetta OR "
# +"FarxigaOR "
# +"KombiglyzeOR "
# +"Onglyza OR "
# +"Symlin OR "
# +"Xigduo/Xigduo XR OR "
# +"Entocort OR "
# +"LosecOR "
# +"Nexium OR "
# +"Vimovo OR "
# +"ApatefOR "
# +"Avloclor OR "
# +"Cubicin OR "
# +"Foscavir OR "
# +"Lexinor OR "
# +"Merrem/Meronem OR "
# +"Paludrine OR "
# +"SavarineOR "
# +"Synagis OR "
# +"Heminevrin OR "
# +"Mysoline OR "
# +"Seroquel OR "
# +"SeroquelOR "
# +"Vivalan OR "
# +"Zomig OR "
# +"Arimidex OR "
# +"Casodex/Cosudex OR "
# +"Faslodex OR "
# +"Iressa OR "
# +"Lynparza OR "
# +"NolvadexOR "
# +"Tomudex OR "
# +"Zoladex OR "
# +"Caprelsa OR "
# +"Tagrisso OR "
# +"Accolate OR "
# +"Bambec OR "
# +"Bricanyl OR "
# +"Oxis OR "
+"Pulmicort"
,
"ytytye9393jenmebrhriue" :
"ytytye9393jenmebrhriue"
}
DATABASES = {'RAW_TWEETS_DB': 'raw_tweets.db',
'FEATURES_DB' : 'extracted_features.db',
'STUB_RAW_TWEETS_DB': 'stub_raw_tweets.db'}
def get_database_connection(db_path):
conn = sqlite3.connect(db_path)
conn.text_factory = str
c = conn.cursor()
return (conn, c)
def create_tweets_table(db_path, table_name):
conn, c = get_database_connection(db_path)
c.execute('''CREATE TABLE IF NOT EXISTS ''' + table_name + \
''' (hash INTEGER PRIMARY KEY, tweet TEXT, ts TEXT)''')
conn.commit()
conn.close()
def get_ticker(company):
response = requests.get(URLS['COMPANY_NAME_TO_TICKER_API'] + company)
response = json.loads(response.content)
return (response[0])['symbol']