def get(self): qdate = datetime.datetime.now().strftime('%Y-%m-%d') qdate = self.get_argument('qdate', qdate) qtime = self.get_argument('qtime', '0') qtables = self.get_arguments('qtable', '0') # Date Time if qtime > 9: qdts = qdate + ' ' + str(qtime) + ':00:00' else: qdts = qdate + ' 0' + str(qtime) + ':00:00' print qdts qdt = datetime.datetime.strptime(qdts, '%Y-%m-%d %H:%M:%S') beginTime = time.mktime(qdt.timetuple()) endTime = beginTime + 3600 #print beginTime dispSeries = [] qtablestr = '' fdb = FDatabase() for qtable in qtables: dispSeries.append(normalize(fdb.queryData(qtable, beginTime, endTime), qtable)) qtablestr += '"' + qtable + '",' qtablestr = qtablestr[0:len(qtablestr) - 1] #print dispSeries[0]['name'] # render template self.render("template/display.html", qdate=qdate, qtime=qtime, qtables=qtablestr, dispSeries=dispSeries)
def dji(): f = urllib2.urlopen('http://stock.finance.sina.com.cn/usstock/api/json.php/US_MinlineNService.getMinline?symbol=.dji&day=5&?=0.4058946408331394') html = f.read() html = html[14:len(html) - 3] # Date Time fetchdtLong = long(time.time()) fetchdate = datetime.datetime.now().strftime('%Y-%m-%d') fetchtime = datetime.datetime.now().strftime('%H:%M:%S') fdb = FDatabase() dayArr = re.split(' ', html) for dayStr in dayArr: sdate = dayStr[0:10] #print sdate for minStr in re.split(';', dayStr[12:]): minArr = re.split(',', minStr) dtime = minArr[0] ddt = datetime.datetime.strptime(sdate + ' ' + dtime, '%Y-%m-%d %H:%M:%S') dlong = time.mktime(ddt.timetuple()) + 12 * 60 * 60 ddt = datetime.datetime.fromtimestamp(dlong) ddate = ddt.strftime('%Y-%m-%d') dtime = ddt.strftime('%H:%M:%S') #print ddate + ' ' + dtime + ' ' + minArr[3] fdb.addData('USADJI', (dlong, ddate, dtime, minArr[3], '', fetchdtLong, fetchdate, fetchtime)) fdb.commit() print 'Importing DJI from sina done!'
def jobPrecialMental(): try: f = urllib2.urlopen( 'http://www.icbc.com.cn/ICBCDynamicSite/Charts/GoldTendencyPicture.aspx', timeout=60) html = f.read() silverRmbPattern = re.compile( r"""人民币账户白银\s*</td>\s*<td[\s\S]+?</td>\s*<td.*?>\s*(.*?)\s*</td> \s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>""", re.S + re.X) goldUsdPattern = re.compile( r"""美元账户黄金 \s*</td>\s*<td[\s\S]+?</td>\s*<td.*?>\s*(.*?)\s*</td> \s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>""", re.S + re.X) agTDPattern = re.compile( r"""Ag\(T\+D\) \s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td[\s\S]+?</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td> \s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td> \s*<td.*?>\s*(.*?)\s*</td>""", re.S + re.X) pmsSilverRmb = silverRmbPattern.search(html) pmsGoldUsd = goldUsdPattern.search(html) pmsAgTD = agTDPattern.search(html) # Date Time fetchdtLong = long(time.time()) fetchdate = datetime.datetime.now().strftime('%Y-%m-%d') fetchtime = datetime.datetime.now().strftime('%H:%M:%S') # Ag T+D Date Time agTddt = datetime.datetime.strptime(pmsAgTD.group(8), '%Y-%m-%d %H:%M:%S') agTdLong = time.mktime(agTddt.timetuple()) agTdDate = agTddt.strftime('%Y-%m-%d') agTdTime = agTddt.strftime('%H:%M:%S') print('fetchdt:' + str(fetchdtLong) + ',fetchdate:' + fetchdate + ',fetchtime:' + fetchtime) print('SilverRmb:' + pmsSilverRmb.group(3) + ',GoldUsd:' + pmsGoldUsd.group(3)) print('AgTd:' + pmsAgTD.group(1) + ', Volume:' + pmsAgTD.group(3) + ', Time:' + pmsAgTD.group(8)) fdb = FDatabase() fdb.addData('SILVERRMB', (fetchdtLong, fetchdate, fetchtime, pmsSilverRmb.group(3), '', fetchdtLong, fetchdate, fetchtime)) fdb.addData('GOLDUSD', (fetchdtLong, fetchdate, fetchtime, pmsGoldUsd.group(3), '', fetchdtLong, fetchdate, fetchtime)) fdb.addAgTd((agTdLong, agTdDate, agTdTime, pmsAgTD.group(1), pmsAgTD.group(3), fetchdtLong, fetchdate, fetchtime)) fdb.commit() except: traceback.print_exc()
def jobPrecialMental(): try: f = urllib2.urlopen("http://www.icbc.com.cn/ICBCDynamicSite/Charts/GoldTendencyPicture.aspx", timeout=60) html = f.read() silverRmbPattern = re.compile( r"""人民币账户白银\s*</td>\s*<td[\s\S]+?</td>\s*<td.*?>\s*(.*?)\s*</td> \s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>""", re.S + re.X, ) goldUsdPattern = re.compile( r"""美元账户黄金 \s*</td>\s*<td[\s\S]+?</td>\s*<td.*?>\s*(.*?)\s*</td> \s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>""", re.S + re.X, ) agTDPattern = re.compile( r"""Ag\(T\+D\) \s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td[\s\S]+?</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td> \s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td>\s*<td.*?>\s*(.*?)\s*</td> \s*<td.*?>\s*(.*?)\s*</td>""", re.S + re.X, ) pmsSilverRmb = silverRmbPattern.search(html) pmsGoldUsd = goldUsdPattern.search(html) pmsAgTD = agTDPattern.search(html) # Date Time fetchdtLong = long(time.time()) fetchdate = datetime.datetime.now().strftime("%Y-%m-%d") fetchtime = datetime.datetime.now().strftime("%H:%M:%S") # Ag T+D Date Time agTddt = datetime.datetime.strptime(pmsAgTD.group(8), "%Y-%m-%d %H:%M:%S") agTdLong = time.mktime(agTddt.timetuple()) agTdDate = agTddt.strftime("%Y-%m-%d") agTdTime = agTddt.strftime("%H:%M:%S") print ("fetchdt:" + str(fetchdtLong) + ",fetchdate:" + fetchdate + ",fetchtime:" + fetchtime) print ("SilverRmb:" + pmsSilverRmb.group(3) + ",GoldUsd:" + pmsGoldUsd.group(3)) print ("AgTd:" + pmsAgTD.group(1) + ", Volume:" + pmsAgTD.group(3) + ", Time:" + pmsAgTD.group(8)) fdb = FDatabase() fdb.addData( "SILVERRMB", (fetchdtLong, fetchdate, fetchtime, pmsSilverRmb.group(3), "", fetchdtLong, fetchdate, fetchtime), ) fdb.addData( "GOLDUSD", (fetchdtLong, fetchdate, fetchtime, pmsGoldUsd.group(3), "", fetchdtLong, fetchdate, fetchtime) ) fdb.addAgTd( (agTdLong, agTdDate, agTdTime, pmsAgTD.group(1), pmsAgTD.group(3), fetchdtLong, fetchdate, fetchtime) ) fdb.commit() except: traceback.print_exc()
def get(self): fdb = FDatabase() op = self.get_argument("op") if op == 'empty': fdb.emptyTables() elif op == 'drop': fdb.dropTables() elif op == 'create': fdb.createTables() self.write("Operation Completed: " + op)
def dji(): f = urllib2.urlopen( 'http://stock.finance.sina.com.cn/usstock/api/json.php/US_MinlineNService.getMinline?symbol=.dji&day=5&?=0.4058946408331394' ) html = f.read() html = html[14:len(html) - 3] # Date Time fetchdtLong = long(time.time()) fetchdate = datetime.datetime.now().strftime('%Y-%m-%d') fetchtime = datetime.datetime.now().strftime('%H:%M:%S') fdb = FDatabase() dayArr = re.split(' ', html) for dayStr in dayArr: sdate = dayStr[0:10] #print sdate for minStr in re.split(';', dayStr[12:]): minArr = re.split(',', minStr) dtime = minArr[0] ddt = datetime.datetime.strptime(sdate + ' ' + dtime, '%Y-%m-%d %H:%M:%S') dlong = time.mktime(ddt.timetuple()) + 12 * 60 * 60 ddt = datetime.datetime.fromtimestamp(dlong) ddate = ddt.strftime('%Y-%m-%d') dtime = ddt.strftime('%H:%M:%S') #print ddate + ' ' + dtime + ' ' + minArr[3] fdb.addData('USADJI', (dlong, ddate, dtime, minArr[3], '', fetchdtLong, fetchdate, fetchtime)) fdb.commit() print 'Importing DJI from sina done!'
def agTD(): f = urllib2.urlopen( "http://www.icbc.com.cn/ICBCDynamicSite/Charts/TimeLine.aspx?pWidth=1010&pHeight=600&dataType=1&dataId=Ag(T%2BD)&picType=3" ) html = f.read() # pattern = re.compile(r"""dataCell\.cell0 = \"(.*?)\";dataCell\.cell1 = \"(.*?)\"""", re.S + re.X) pattern = re.compile( r"""dataCell\.cell0\s=\s\"(.*?)\";dataCell\.cell1\s=\s\"(.*?)\";dataCell.cell2\s=\s\"(.*?)\";""", re.S + re.X ) # Date Time fetchdtLong = long(time.time()) fetchdate = datetime.datetime.now().strftime("%Y-%m-%d") fetchtime = datetime.datetime.now().strftime("%H:%M:%S") fdb = FDatabase() for m in re.finditer(pattern, html): # print '%02d-%02d: %s, %s, %s' % (m.start(), m.end(), m.group(1), m.group(2), m.group(3)) agTddt = datetime.datetime.strptime(m.group(1), "%Y-%m-%d %H:%M:%S") agTdLong = time.mktime(agTddt.timetuple()) agTdDate = agTddt.strftime("%Y-%m-%d") agTdTime = agTddt.strftime("%H:%M:%S") fdb.addAgTd((agTdLong, agTdDate, agTdTime, m.group(2), "0", fetchdtLong, fetchdate, fetchtime)) fdb.commit() print "Importing agtd from icbc done!"
def usdx(): f = urllib2.urlopen('http://quote.forex.hexun.com/ForexXML/MI_CUR5/MI_CUR5_5_usdx.xml?&ts=1376574847490') html = f.read() root = minidom.parseString(html) # Date Time fetchdtLong = long(time.time()) fetchdate = datetime.datetime.now().strftime('%Y-%m-%d') fetchtime = datetime.datetime.now().strftime('%H:%M:%S') fdb = FDatabase() for item in root.getElementsByTagName("Item"): usdxPr = item.getElementsByTagName("PR")[0].childNodes[0].nodeValue usdxTm = item.getElementsByTagName("ST")[0].childNodes[0].nodeValue usdxTm = '2013' + usdxTm + '00' # USDX Date Time usdxdt = datetime.datetime.strptime(usdxTm, '%Y%m%d%H%M%S') usdxLong = time.mktime(usdxdt.timetuple()) usdxDate = usdxdt.strftime('%Y-%m-%d') usdxTime = usdxdt.strftime('%H:%M:%S') fdb.addUsdx((usdxLong, usdxDate, usdxTime, usdxPr, '', fetchdtLong, fetchdate, fetchtime)) fdb.commit() print 'Importing USDX from hexun done!'
def agTD(): f = urllib2.urlopen( 'http://www.icbc.com.cn/ICBCDynamicSite/Charts/TimeLine.aspx?pWidth=1010&pHeight=600&dataType=1&dataId=Ag(T%2BD)&picType=3' ) html = f.read() #pattern = re.compile(r"""dataCell\.cell0 = \"(.*?)\";dataCell\.cell1 = \"(.*?)\"""", re.S + re.X) pattern = re.compile( r"""dataCell\.cell0\s=\s\"(.*?)\";dataCell\.cell1\s=\s\"(.*?)\";dataCell.cell2\s=\s\"(.*?)\";""", re.S + re.X) # Date Time fetchdtLong = long(time.time()) fetchdate = datetime.datetime.now().strftime('%Y-%m-%d') fetchtime = datetime.datetime.now().strftime('%H:%M:%S') fdb = FDatabase() for m in re.finditer(pattern, html): #print '%02d-%02d: %s, %s, %s' % (m.start(), m.end(), m.group(1), m.group(2), m.group(3)) agTddt = datetime.datetime.strptime(m.group(1), '%Y-%m-%d %H:%M:%S') agTdLong = time.mktime(agTddt.timetuple()) agTdDate = agTddt.strftime('%Y-%m-%d') agTdTime = agTddt.strftime('%H:%M:%S') fdb.addAgTd((agTdLong, agTdDate, agTdTime, m.group(2), '0', fetchdtLong, fetchdate, fetchtime)) fdb.commit() print 'Importing agtd from icbc done!'
def silverRmb(): f = urllib2.urlopen( 'http://www.icbc.com.cn/ICBCDynamicSite/Charts/TimeLine.aspx?pWidth=1010&pHeight=600&dataType=0&dataId=903&picType=3' ) html = f.read() #pattern = re.compile(r"""dataCell\.cell0 = \"(.*?)\";dataCell\.cell1 = \"(.*?)\"""", re.S + re.X) pattern = re.compile( r"""dataCell\.cell0\s=\s\"(.*?)\";dataCell\.cell1\s=\s\"(.*?)\";dataCell.cell2\s=\s\"(.*?)\";""", re.S + re.X) # Date Time fetchdtLong = long(time.time()) fetchdate = datetime.datetime.now().strftime('%Y-%m-%d') fetchtime = datetime.datetime.now().strftime('%H:%M:%S') fdb = FDatabase() for m in re.finditer(pattern, html): #print '%02d-%02d: %s, %s, %s' % (m.start(), m.end(), m.group(1), m.group(2), m.group(3)) ddt = datetime.datetime.strptime(m.group(1), '%Y-%m-%d %H:%M:%S') dlong = time.mktime(ddt.timetuple()) ddate = ddt.strftime('%Y-%m-%d') dtime = ddt.strftime('%H:%M:%S') fdb.addData('SILVERRMB', (dlong, ddate, dtime, m.group(2), '', fetchdtLong, fetchdate, fetchtime)) fdb.commit() print 'Importing silver rmb from icbc done!'