def create_viewfiles(tarray): oldfile = viewsdir + 'list_' + oldword + '.html' oldfilev = viewsdir + 'view_' + oldword + '.html' print oldfile for tname in tarray: newword = tname newfile = viewsdir + 'list_' + newword + '.html' newwordplural = newword + 's' oldwordplural = oldword + 's' print 'foundoone', newfile newfile = viewsdir + 'list_' + newword + '.html' newfilev = viewsdir + 'view_' + newword + '.html' if os.path.isfile(newfile): os.remove(newfile) if os.path.isfile(newfilev): os.remove(newfilev) lines = rpu_rp.TxtToLines(oldfile) for line in lines: newline = line.replace(oldwordplural, newwordplural).replace(oldword, newword) rpu_rp.WriteStringsToFileAppend(newfile, newline) linesv = rpu_rp.TxtToLines(oldfilev) for line in lines: newline = line.replace(oldwordplural, newwordplural).replace(oldword, newword) rpu_rp.WriteStringsToFileAppend(newfilev, newline)
def tnamearray(): tlist = modelsdir + 'tableslist.txt' tlistarray = rpu_rp.TxtToLines(modelsdir + 'sugar3_db.py') fieldlistarray = rpu_rp.TxtToLines(modelsdir + 'tablesNfields.csv') tarray = [] farray = [] for l in tlistarray: if 'db.define_table' in l: tname = l.split('\'')[1] print tname tarray.append(tname) return tarray
def revise_tpl_file(filein,mode,search,replacer): lines = rpu_rp.TxtToLines(filein) tag=text='' for l in lines: ## print l lsplit=str(l).split('\'') if len(lsplit) >3: tag=lsplit[1] text=lsplit[3] if mode == 'all': print tag, '>>>',text pass elif mode == 'replace': tag1=search tag2=replacer newl = str(l).replace(tag1,tag2) print newl pass elif mode == 'grep': tag1=search tag2=replacer newl = str(l).replace(tag1,tag2) if search in str(l) or replacer in str(l): print l pass else: pass
def search_for_words(): tradewords =['Tightening risk point','New pending shorts','triggered','Reinstating','pyramid',\ 'EXECUT','AUDIBLE:','Covering','Covered','Sold', 'Bought', 'LONG', 'SHORT '] for word in tradewords: print word for line in rpu_rp.TxtToLines(filein): if word.upper() in (str(line)).upper(): ## print line pass
def write_fdbase(tname): basicfieldsfile = 'basicDbaseFields.csv' basiclinesarray = rpu_rp.TxtToLines(basicfieldsfile) print 'db.define_table(' + '\'' + tname + '\'' + ',' countb = 0 for b in basiclinesarray: countb += 1 bs = b.split(',') lengthf = bs[3].strip() if countb < 43333: print ',' + tname + ',' + bs[1] + ',' + bs[2] + ',' + bs[ 3] + ',defquired=False),'
def copyfiles(oldword, newword): newwordplural = newword + 's' oldwordplural = oldword + 's' oldfile = viewssugardir + 'list_' + oldword + '.html' newfile = viewsdir + 'list_' + newword + '.html' lines = rpu_rp.TxtToLines(oldfile) os.system('rm ' + newfile) for line in lines: newline = line.replace(oldword, newword).replace(oldwordplural, newwordplural) rpu_rp.WriteStringsToFileAppend(newfile, newline)
def write_basicdbase(tname): basicfieldsfile = 'basicDbaseFields.csv' basiclinesarray = rpu_rp.TxtToLines(basicfieldsfile) print 'db.define_table(' + '\'' + tname + '\'' + ',' countb=0 for b in basiclinesarray: countb +=1 bs = b.split(',') lengthf = bs[3].strip() if countb < 4: if lengthf =='': print 'Field(\''+bs[1].strip()+'\', \''+bs[2].strip()+'\', '+'default=None, required=False),' pass else: print 'Field(\''+bs[1].strip()+'\', \''+bs[2].strip()+'\', '+bs[3].strip()+',default=None, required=False),'
def write_fdbase(tname): basicfieldsfile = 'basicDbaseFields.csv' basicfieldsfile = modelsdir + 'sugar3_db.py' basiclinesarray = rpu_rp.TxtToLines(basicfieldsfile) countb=0 tnameloc = '' for l in basiclinesarray: ## print l if 'db.define_table' in l: tnameloc= l.split('\'')[1] ## print tnameloc countb +=1 bs = l.split(',') ## print bs ## lengthf = bs[3].strip() if len(bs) > 3 and tnameloc == tname: print ','+tname+','+bs[0].strip()+','+bs[1]+','+bs[2]+',defquired=False),'
def check_for_entry_fills(profitorder,order_id): ordersfname = 'entryorderssent' lines = rpu_rp.CsvToLines(ordersfname) for l in lines: executedf = 'open' print l ## order_id = 22 filltag = 'orderId=' + str(order_id) + ', status=Filled' ## for order id, look fora fill for b in rpu_rp.TxtToLines('replys'): if 'orderStatus' in str(b) and filltag in str(b): print b executedf = 'filled' print executedf, 'placing prof ord if filled' executedf = 'filled' ##### hack for testing to force the proforder if executedf == 'filled': print 'sending prof' ## cannot use this order, it is stale, need to rebuild order based on the dictionary ##created in order creation, tag the orders in the dictionary as entry,profit,filled,open and use this ## newpoorder = ibutiles.create_order('LMT', tsize, flipside, profprice,True,profprice,profprice,'profit') ## need to add profit amount based ona dictionary created before tws_conn.placeOrder(order_id + 1, symcontract, profitorder)
def parse_merc_input(filein): #### build the month dictionary from text to unix values ### monthdict = {} mlist = ['January', 'February','March', 'April', 'May','June','July','August','September','October','November','December'] count =1 for mth in mlist: if count < 10: monthdict[mth.upper()] = '0' + str(count) else: monthdict[mth.upper()] = '' + str(count) count +=1 ##################### create the trades database based on keywords for trades #### linesin = rpu_rp.TxtToLines(filein) count = 0 trades =[] datedline = newdate ='need this need | | | ' for line in linesin: count += 1 if count < 300000: ## <div class="post-byline">9:02 am - January 13, 2014 <meta http-equi if '<div class="post-byline">' in line: newdate=line.replace('<','>').split('>')[2] ## print newdate triggerwordlist = ['TRIGGERED','COVERED','EXECUTED','HIT OUR RISK POINT','BOUGHT','SOLD'] for word in triggerwordlist: if word in str(line).upper(): datedline = line.upper().strip() + '...' + newdate.upper() trades.append(datedline) #################### ##################### create stock list stocklist =[] for l in trades: ## print l splitline = l.replace('–','|') spl2 = splitline.replace('–','|') sp3 = spl2.split('|') if len(sp3) == 3 and "," in sp3[0]: print len(sp3), sp3 if ';' in l and '@' in l: if '–;;;;' in l: print l ## <p>LPX, YUM triggered – short LPX @ 13.67 – short YUM @ 67.61</p>...12:52 pm - September 25, 2012 stock = l.split()[2] stock2 = l.split()[1] stocklist.append(stock) stocklist.append(stock2) ################ ############### ustklist = rpu_rp.uniqArray(stocklist) price = 'xx' linenum = 0 tradelist =[] datelines = [] ### end of building stocklist ## for s in ustklist: tradeside = 'long' lengths = len(s) symbolfromlist = '' + s.upper() print s, symbolfromlist if 'AMTD' not in s and lengths >2 and lengths <5: searchp = 'x' ## print ' ====== ' + searchp + ' ======' for lineraw in trades: line2 = lineraw.upper() ## print line2 symbolline = line2.replace('€“','').replace('–','') symbol = symbolline.split()[1] tradeside = 'long' if symbolfromlist == symbol : ## print 'found match' ## print '###',symbol,'###' newline = (line2.replace('<LI>','|')).split('|') newlinedate = (line2.replace('...','|')).split('|') newlineprice = (line2.replace('</LI>','@')).split('@') if 'SHORT' in str(line2) or 'SELL' in str(line2) or 'SOLD' in str(line2): tradeside = 'sell' if '5-min rule'.upper() in str(line2): tradeside = 'notrade' if 'covered'.upper() in str(line2) : tradeside = 'coverfull' if 'covered half'.upper() in str(line2) : tradeside = 'coverhalf' if '@' in str(line2): price = newlineprice[1] try: trdmssg = newline[1] except: trdmssg = 'badline' ## print trdmssg, 'mssg', price, searchp, linenum, tradeside, newlinedate[1] fulltrade = [] dateline =[] txtdatemth = newlinedate[1].split()[3] ## print txtdatemth try: unixdatemth = monthdict[txtdatemth] ## print line2 except: print newlinedate print line2 unixdatemth = 'BLAAA' unixdateyr = newlinedate[1].split()[5] unixdateday = newlinedate[1].split()[4] if len(unixdateday) == 2: realday = ('0' + unixdateday).replace(',','') else: realday = ('' + unixdateday).replace(',','') dateline.append(linenum) dateline.append(unixdateyr + unixdatemth + realday) datelines.append(dateline) fulltrade.append('1')#linenum) fulltrade.append(symbol) fulltrade.append(price) fulltrade.append(tradeside) fulltrade.append(unixdateyr + unixdatemth + realday) tradelist.append(fulltrade) linenum += 1 prevstocksym = 'bla' datesarray =[] sortedtrades = sorted(tradelist, key=lambda bla: bla[1], reverse=True) sorted(tradelist, key=lambda bla: bla[1], reverse=True) rpu_rp.WriteArrayToCsvfile('blatrades.csv',sortedtrades) for t in sortedtrades: date = t[1] datesarray.append(date) udates = rpu_rp.uniqArray(datesarray) return sortedtrades
for var in nd.keys(): locals()[var] = nd[var] import ENVdicts nd ={} nd = ENVdicts.ENVdicts(localtag) for var in nd.keys(): locals()[var] = nd[var] #################### import rpu_rp downloads = 'C:/Users/bob/Downloads/' fname = 'bingos py - Sheet1.csv' fname = 'BINGO RPADV - Sheet1.csv' f= EXE + fname for b in rpu_rp.TxtToLines(f): if 'UT' in b: print b dictbingos = rpu_rp.create_dict(f,0,1) ##print dictbingos.items() keys = raw_input('enterkeys here with . separator... ') ##key1 = '155' ##key2 = '134' key1=keys.split('.')[0] key2=keys.split('.')[1] fullkey = dictbingos[key1] + dictbingos[key2] print 'here is the key...\n'
################################ EXE = EXEnoslash + '/' DATA = rootpath + 'DATA' + localtagSLASH TMP = rootpath + 'TMP' + localtagSLASH ActantData = 'C:/Program Files/Actant/Log/' ActantDataNoSlash = 'C:/Program Files/Actant/Log' todayf = 'AQTOR_20150408_1.log' todayf = 'bla' ##def grep_to_txtfile(infilename,greppattern,outfilename,fieldnum): ####################################################### for f in os.listdir(ActantDataNoSlash): print f ##fblaw = raw_input('enter filename here: ') ##rpu_rp.WriteStringsToFileAppend(ActantData + f,f) ##array = rpu_rp.grep_txtfile_to_array(ActantData + todayf,'Scr') lines = rpu_rp.TxtToLines(ActantData + todayf) barsize = 3 bartime = 6000 barhi = 0 barlo = 99999999 tickcount = tottickcount = 0 bararray = [] prevtime = 0 timestart = 0 for line in lines: if '6E' in str(line): tickcount += 1
locals()[var] = nd[var] ################## global timedate_format, nextorderID, date, today, recentlimit, time_format, sym, symbol_list, symdict moduleNames = ['rpu_rp'] #open(EXE +'importmodlist.txt').readlines() for module in moduleNames: modulestripped = module.strip() if modulestripped != titleself: ## print '...',modulestripped,'xxx',titleself my_module = importlib.import_module(modulestripped) pass else: print 'is self' ##################### controllerfile = 'C:/WEB2PY/EXE_RP/web2py/applications/AddfinV3/controllers/default.py' tnamescontroller = [] for l in rpu_rp.TxtToLines(controllerfile): if ',False,url(' in l: tname = l.split(',')[0].split('\'')[1] tnamescontroller.append(tname) print tnamescontroller ############################ def write_sqlite(tablename, fieldarray, formatdict, defvaluedict): import fileinput fnames = fieldarray #['name','role'] for line in ['1']: #fileinput.input('newtablelist'): tname = tablename # line.strip() print 'db.define_table(' + '\'' + tname + '\'' + ',' fncount = 0 for fn in fnames:
tablename = fheader = '' numrecords = 1 fheaderflag = contentsflag = 'n' dbnamefull = dbname # heredir +dbname fheaderarray = [] fheaderformatarray = [] fheaderdefvaluearray = [] fheadformatdict = {} fheaddefvaluedict = {} tablenames = ['contacts', 'accounts'] prevtablename = '' newfieldsflag = 'n' print '#####################################' outputarea = downloads + 'outtemp/' tablenametarget = 'DatabaseProducts' for l in rpu_rp.TxtToLines(dbnamefull): line = str(l) rline = line.replace('),(', '|').replace('VALUES (', '|') if 'DROP TABLE IF EXISTS' in str(l): bla = [] tablename = l.split()[4].replace('`', '').replace(';', '') rpu_rp.WriteArrayToCsvfile(outputarea + tablename + 'dbtable.csv', bla) newtflag = newfieldsflag = 'y' if 'INSERT INTO' in str(l): newfieldsflag = 'n' if 'CREATE TABLE' in str(l): fheaderflag = 'y' if 'KEY' in str(l) or 'ENGINE' in str(l): fheaderflag = 'n'
def convert_emailtolines(): wbfile = downloads +'BlountNewEmail.txt' wbfile = 'BlountNewEmail.txt' lines = rpu_rp.TxtToLines(wbfile) full=[] readflag ='n' label = 'WBs_' prevline = [] prevlabel = '' fullarray =[] for l in lines: rowarray =[] sline = ' '.join(l.split()).replace('MAX ','MAX').replace('TWO DAY','TWODAY') linelength = len(sline.split()) b = sline c = sline.split() if 'Range Projections' in str(l): label = 'Range_' elif 'TVS' in str(l): label = 'TVS' elif 'TWODAY' in str(sline): label = 'TWODAY_' elif 'OPG' in str(l): label = 'prev_' else: pass if 'JUNE 2016 contract' in str(l): readflag = 'y' if '*email*: [email protected]' in str(l): readflag = 'n' if readflag == 'y' and linelength > 0: if len(c) == 1 and len(prevline) > 1 : if prevlabel == 'WBs_' or prevlabel == 'prev_': dval = prevline[1] wval = c[0] maintag = prevlabel+prevline[0] for dwtag in ['_DAY','_WEEK']: tag = maintag+dwtag if dwtag == '_DAY': val = dval pass else: val = wval if val != 'DAILY': rowarray=[val,tag] fullarray.append(rowarray) ######### if prevlabel == 'Range_': rangedesc = prevline[1] for rangetag in ['Low_','Hi__']: for dwtag in ['_DAY','_WEEK']: if rangetag == 'Low_' and dwtag == '_DAY': val = prevline[0].split('-')[0] if rangetag == 'Hi__' and dwtag == '_DAY' : val = prevline[0].split('-')[1] if rangetag == 'Low_' and dwtag == '_WEEK': val = c[0].split('-')[0] if rangetag == 'Hi__' and dwtag == '_WEEK': val = c[0].split('-')[1] ## if 'alternate' not in rangedesc: rowarray=[val,prevlabel+rangetag+rangedesc +dwtag] fullarray.append(rowarray) ############################## if len(c) > 1 and len(prevline) > 1 and prevlabel == 'TWODAY_': dvallow = prevline[0].split('-')[0] dvalhii = prevline[0].split('-')[1] rangedesc = prevline[1] wval = c[0] tag = prevlabel+'Low_'+rangedesc +'_2DAY\n' val = dvallow rowarray=[val,tag] fullarray.append(rowarray) tag = prevlabel+'Hi__'+rangedesc +'_2DAY\n' val = dvalhii rowarray=[val,tag] fullarray.append(rowarray) prevline = c prevlabel = label fname = libarea + 'SpotsWBDaily.ES.txt' rpu_rp.WriteArrayToCsvfile(fname,fullarray)
netpos = value2 total += float(t[2]) * netpos print t, total prevstocksym = stocksym f.close() ##################### ####################### filein = 'mercwebscrapepages.0.100.txt' ##filein = path + 'mercwebscrapepages.txt' dothis = parse_merc_input(filein) ########################## tradewords =['Tightening risk point','New pending shorts','triggered','Reinstating','pyramid','executed','AUDIBLE:','Covering','Covered'] for word in tradewords: for line in rpu_rp.TxtToLines(filein): if word in str(line): ## print line pass ## if '2013' in line: ## print line ## date = str(liner[0:5]) ## liner.append(date) ## if 'Trade Log' in line or 'Trade Alert' in line or 'Trade Note' in line: ## flagon ='y' ## if line == '\n': ## print line ## if line == '' and doublespace != 'y': ## linegaps = '1' ## print line
def grablinkpages(filein): for l in rpu_rp.TxtToLines(filein): if 'href="http://www.mercenarytrader.net/' in l and 'more' in l: print l