-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataCollection.py
More file actions
66 lines (51 loc) · 2.76 KB
/
Copy pathDataCollection.py
File metadata and controls
66 lines (51 loc) · 2.76 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
import DataStructure
__author__ = 'WHAAAAAAAt'
import urllib2
import json
import node1
import datetime
import time
import threading2
from threading2 import *
#we need to put all the data collection logic here
#the work which was done yesterday will go here
class DataCollection():
def producerFunctions(self,dataStructure ):
# we need to the frequency of server ping for each stock
# possible changes in the looping structure
# All data needs to be stored in the arg.stockHash[<company code>]
googleURL='http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22GOOG%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback='
yahooURL='https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22YHOO%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback='
appleURL='https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22AAPL%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback='
while (True):
ts=time.time()
#google quote ping
weburl = urllib2.urlopen(googleURL)
data = weburl.read()
da=json.loads(data)
google=node1.node1( datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') ,str(da['query']['results']['quote']['LastTradePriceOnly']))
#yahoo quote ping
weburl = urllib2.urlopen(yahooURL)
data = weburl.read()
da=json.loads(data)
yahoo=node1.node1( datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') ,str(da['query']['results']['quote']['LastTradePriceOnly']))
#google quote ping
weburl = urllib2.urlopen(appleURL)
data = weburl.read()
da=json.loads(data)
apple=node1.node1( datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') ,str(da['query']['results']['quote']['LastTradePriceOnly']))
#acquire locks
dataStructure.lock.acquire(shared = True )
try:
dataStructure.stockHash["Google"].append(google)
dataStructure.stockHash["Apple"].append(apple)
dataStructure.stockHash["Yahoo"].append(yahoo)
finally:
dataStructure.lock.release()
#revoke lock
#wait until refresh time expires
time.sleep(3)
'''
for company in dataStructure.stockHash:
print "company has # of values "+ company +" "+ str(len(dataStructure.stockHash[company]))
'''