Created
March 25, 2013 13:00
-
-
Save bumbu/5236936 to your computer and use it in GitHub Desktop.
Script that gathers data from wm.exchanger.ru. More info here http://wm.exchanger.ru/asp/rules_xml.asp
I was running it using a cron job every 3 minutes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
from datetime import date, datetime | |
import os | |
# ######################################################## | |
# Definitions | |
# ######################################################## | |
DIRECTORY = 'ADD HERE OUTPUT DIRECTORY' | |
links = { | |
'rates_plus': 'https://wm.exchanger.ru/asp/XMLbestRates.asp' | |
, 'rates_minus': 'https://wm.exchanger.ru/asp/XMLbestRatesMinus.asp' | |
} | |
bids_link = 'https://wm.exchanger.ru/asp/XMLWMList.asp?exchtype=' | |
# ######################################################## | |
# Functions | |
# ######################################################## | |
def createTodayFolder(): | |
today = str(date.today()) | |
print "Check if folder "+today+" exists" | |
directory = os.path.join(DIRECTORY, today) | |
if not os.path.exists(directory): | |
print "Folder "+today+" does not exists" | |
try: | |
os.makedirs(directory) | |
print "Created folder "+today | |
except OSError: | |
print "Error while creating folder "+today | |
return false | |
return directory | |
def download(link, name = ''): | |
print 'Start processing link ' + str(name) | |
# timestamp | |
now = datetime.now().strftime("%H:%M") | |
u = urllib2.urlopen(link) | |
localFile = open(folder+'/'+now+name+'.xml', 'w') | |
localFile.write(u.read()) | |
localFile.close() | |
# ######################################################## | |
# Body | |
# ######################################################## | |
folder = createTodayFolder() | |
if(folder): | |
# rates | |
for link in links: | |
download(links[link], link) | |
# bids | |
for i in range(1, 33): | |
download(bids_link+str(i), 'bid_'+str(i)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment