Skip to content

Instantly share code, notes, and snippets.

@mallocnode
Last active January 15, 2016 09:57
Show Gist options
  • Save mallocnode/1188a58b1a1f09ff4bb2 to your computer and use it in GitHub Desktop.
Save mallocnode/1188a58b1a1f09ff4bb2 to your computer and use it in GitHub Desktop.
#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
import message_sender
#ho_ko_dollar_to_eur take a list of
#values and: convert it in float and €
def ho_ko_dollar_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except:
print('Error in ho_ko_dollar_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.1146)))
return new_values
#pound_to_eur take a list of
#values and: convert it in float and €
def pound_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except:
print('Error in pound_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*1.38653389)))
return new_values
#s_cor_won_to_eur take a list of
#values and: convert it in float and €
def s_cor_won_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except:
print('Error in s_cor_won_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.00076643954)))
return new_values
#cil_pes_to_eur take a list of
#values and: convert it in float and €
def s_cor_won_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except:
print('Error in cil_pes_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.0013)))
return new_values
#can_dollars_to_eur take a list of
#values and: convert it in float and €
def can_dollars_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except :
print('Error in can_dollars_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.670910)))
return new_values
#newzel_dollars_to_eur take a list of
#values and: convert it in float and €
def newzel_dollars_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except :
print('Error in newzel_dollars_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.617988)))
return new_values
#rupiah_to_eur take a list of
#values and: convert it in float and €
def rupiah_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except :
print('Error in rupiah_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.00028)))
return new_values
#colo_pes_to_eur take a list of
#values and: convert it in float and €
def col_pes_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except :
print('Error in col_pes_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.00027)))
return new_values
#bri_puond_to_eur take a list of
#values and: convert it in float and €
def bri_puond_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except :
print('Error in bri_puond_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.0251015736)))
return new_values
#cor_swe_to_eur take a list of
#values and: convert it in float and €
def cor_swe_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except :
print('Error in cor_swe_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.107311)))
return new_values
#usd_to_eur take a list of
#values and: convert it in float and €
def usd_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except :
print('Error in usd_to_eur.'+'The values in the list can\'t be converted')
message_sender.send('Error in Usd_to_eur. Probably a new value')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.92357)))
return new_values
#yen_to_eur take a list of
#values and: convert it in float and €
def yen_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except:
print('Error in yen_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.14074)))
message_sender.send('Fucking cinese currency')
return new_values
#mal_rig_to_eur take a list of
#values and: convert it in float and €
def mal_rig_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except:
print('Error in mal_rig_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.211740)))
return new_values
#bra_dollars_to_eur take a list of
#values and: convert it in float and €
def bra_dollars_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except:
print('Error in bra_dollars_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.241374018)))
return new_values
#swiss_franc_to_eur take a list of
#values and: convert it in float and €
def swiss_franc_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except:
print('Error in swiss_franc_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.924997841)))
return new_values
#lir_turc_to_eur take a list of
#values and: convert it in float and €
def lir_turc_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except:
print('Error in lir_turc_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.312207)))
return new_values
#sig_dollars_to_eur take a list of
#values and: convert it in float and €
def sig_dollars_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except:
print('Error in sig_dollars_to_eur.'+r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.8599)))
return new_values
#convert_py6_to_eur take a list of
#values and: convert it in float and €
def py6_to_eur(values):
new_values=[]
if len(values)<1:
return values
#convert to float and handle errors
try:
values=to_float(values)
except:
print('Error in py6_to_eur.',r'The values in the list can\'t be converted')
#create new list with eur values
for item in values:
new_values.append(float('%.2f' % float(item*0.0130854696921585)))
return new_values
#to_float take a string
# and convert it to float
#It replace the "," with "."
def to_float(string_list):
if len(string_list)<1:
return string_list
i=0
while i<len(string_list):
string_list[i]=string_list[i].replace(',','.')
string_list[i]=float(string_list[i])
i+=1
return string_list
#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
import re
import convert_price, message_sender
#html_filter take one html source
#code and take all the price
#it return a list with all the price
#converted in €
def html_source(source):
#take the various values in the source
#NOTA:not all the currencies are recognized
no_filtered_price=re.findall('<span class="market_listing_price market_listing_price_with_fee">\s+(.+)\t\t\t\t\t</span>',source.decode('utf-8'))
price=list_of_price(no_filtered_price)
price=sorted(price)
return price
#list_of_price take a list of string
#and convert it in float values if
#they contain numerical values
def list_of_price(no_filtered_list):
eur_price=[]
py6_price=[]
newzel_dol_price=[]
canadian_dollar=[]
bri_pound=[]
usd_price=[]
bra_dollars_price=[]
lir_turc_price=[]
sig_dollar=[]
yen_price=[]
cor_swe_price=[]
swiss_franc_price=[]
ho_ko_dollar=[]
rupiah=[]
col_dollar=[]
pound=[]
s_cor_won=[]
mal_rig=[]
clp=[]
for item in no_filtered_list:
if '--' in item:
item=item.replace('--','').replace(' ','')
if 'p\u0443\u0431.' in item:
py6_price.append(item.replace('p\u0443\u0431.','').replace(' ',''))
elif 'NZ$' in item:
newzel_dol_price.append(item.replace('NZ$','').replace(' ',''))
elif 'CLP$' in item:
newzel_dol_price.append(item.replace('CLP$','').replace(' ','').replace('.',''))
elif 'HK$' in item:
newzel_dol_price.append(item.replace('HK$','').replace(' ',''))
elif 'COL' in item:
col_dollar.append(item.replace('COL','').replace(' ','').replace('$','').replace('.',''))
elif 'CHF' in item:
swiss_franc_price.append(item.replace('CHF','').replace(' ',''))
elif '\u00A3' in item:
pound.append(item.replace('\u00A3','').replace(' ',''))
elif 'CDN$' in item:
canadian_dollar.append(item.replace('CDN$','').replace(' ',''))
elif 'RM' in item:
mal_rig.append(item.replace('RM','').replace(' ',''))
elif 'USD' in item:
usd_price.append(item.replace('USD','').replace('$','').replace(' ',''))
elif '€' in item:
eur_price.append(item.replace('€','').replace(' ',''))
elif 'R$' in item:
bra_dollars_price.append(item.replace('R$','').replace(' ',''))
elif 'S$' in item:
sig_dollar.append(item.replace('S$','').replace(' ',''))
elif 'TL' in item:
lir_turc_price.append(item.replace('TL','').replace(' ',''))
elif '\u00A5' in item:
yen_price.append(item.replace('\u00A5','').replace(' ','').replace(',',''))
elif 'kr' in item:
cor_swe_price.append(item.replace('kr','').replace(' ',''))
elif '฿' in item:
bri_pound.append(item.replace('฿','').replace(' ',''))
elif 'Rp' in item:
rupiah.append(item.replace('Rp','').replace(' ',''))
elif '₩' in item:
s_cor_won.append(item.replace('₩','').replace(' ','').replace(',',''))
elif '$' in item:
usd_price.append(item.replace('$','').replace(' ',''))
message_sender.send('new dollar currency'+str(item))
else:
message_sender.send('New match ' +str(item))
price=convert_price.py6_to_eur(py6_price)+convert_price.usd_to_eur(usd_price)+\
convert_price.to_float(eur_price)+convert_price.newzel_dollars_to_eur(newzel_dol_price)+\
convert_price.can_dollars_to_eur(canadian_dollar)+convert_price.pound_to_eur(pound)+\
convert_price.bra_dollars_to_eur(bra_dollars_price)+convert_price.sig_dollars_to_eur(sig_dollar)+\
convert_price.lir_turc_to_eur(lir_turc_price)+convert_price.yen_to_eur(yen_price)+\
convert_price.cor_swe_to_eur(cor_swe_price)+convert_price.swiss_franc_to_eur(swiss_franc_price)+\
convert_price.ho_ko_dollar_to_eur(ho_ko_dollar)+convert_price.rupiah_to_eur(rupiah)+\
convert_price.col_pes_to_eur(col_dollar)+convert_price.bri_puond_to_eur(bri_pound)+\
convert_price.s_cor_won_to_eur(s_cor_won)+convert_price.mal_rig_to_eur(mal_rig)+convert_price.col_pes_to_eur(clp)
return price
#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
import sys, time,random
import op_list
import message_sender
def main():
file1=sys.argv[1]
file2=sys.argv[2]
#this list will save the current price on the file2
#so you will not get error when calling the
# check_threshold function
op_list.save_price(file2,op_list.create_list_of_price(op_list.read_file(file1)))
while True:
try:
price=op_list.create_list_of_price(op_list.read_file(file1))
op_list.check_threshold(file2,price)
op_list.save_price(file2,price)
time.sleep(random.randint(300,350))
except:
message_sender.send('Some error in main')
if __name__ == '__main__':
main()
#!/usr/bin/env python2 -tt
# -*- coding: utf-8 -*-
import telebot
#set bot token
bot=telebot.TeleBot('your token here')
#send the message to the bot
def send(message):
chatid=00000000 #your chat id here
bot.send_message(chatid,message)
#!/usr/bin/python -tt
# -*- coding: utf-8 -*-
import re
import filter
import message_sender
import time,random
from urllib.request import urlopen
#read_file for each line in the file
#save string in a list then call
#split_list
def read_file(filename):
l_link_no_split = open(filename, 'rU').readlines()
return split_list(l_link_no_split)
#split_list divide each string
#of each element in the list_from_file
#and for each list is saved in a new list(of list)
def split_list(list_from_file):
l_split = []
for item in list_from_file:
l_split.append(item.split(', '))
return l_split
#create_list_of_price take a list of
#link and return a list of all the
# price in it
def create_list_of_price(list_of_link):
list_of_price=[]
i = 0
while i< len(list_of_link):
try:
time.sleep(random.randint(10,15))
html_source = urlopen(list_of_link[i][2]).read()
except:
message_sender.send('Probably some error loading the link')
pass
list_of_price.append([list_of_link[i][0]]+[list_of_link[i][1]]+filter.html_source(html_source))
i+=1
return list_of_price
#calculate_threshold calculate the
#threshold of a given list
def calculate_threshold(price):
threshold=price-price*15/100
return threshold
#check_last_price take all the list
#from the file and for each list
#calculate the min value, it return
#a list of all the min value
def check_last_price(filename):
old_price=[]
price=read_file(filename)
app=[]
for item in price:
i=0
while i<len(item):
o=(item[i].replace('\n',''))
o=re.findall('\d+.\d+',o)
if o :
app.append(float(o[0]))
i+=1
app=map(float,app)
ok=min(app)
old_price.append(ok)
app=[]
return old_price
#save_price write the list_of_item
#in the given filename
def save_price(filename,list_of_item):
f=open(filename,'w')
for item in list_of_item:
f.write(str(item).replace('[','').replace(']','').replace('\'',''))
f.write('\n')
f.close()
#check_threshold send the message
#if the threshold condition is
#true
def check_threshold(filename,li):
la=check_last_price(filename)
i=0
while i<len(li):
#threshold condition
try:
if li[i][2]<calculate_threshold(la[i]):
message_sender.send(str(li[i][1])+str(' ')+str(li[i][2]))
i+=1
except:
message_sender.send(str('len la')+str(len(la)+str('len li')+str(len(li))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment