Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Monday, November 16, 2015

Python: Retrieve files from URL link

file-retrieve-via-url.py
#!/usr/bin/env python
import urllib
from datetime import datetime

saveFileName = "Sydney-Auction-Result-"+datetime.now().strftime("%Y%m%d%H%M%S")+".pdf"
urllib.urlretrieve ("http://domainmastheads.homepriceguide.com.au/saturday_auction_results/Sydney.pdf",saveFileName )
saveFileName = "Adelaide-Auction-Result-"+datetime.now().strftime("%Y%m%d%H%M%S")+".pdf"
urllib.urlretrieve ("http://domainmastheads.homepriceguide.com.au/saturday_auction_results/Adelaide.pdf",saveFileName )
saveFileName = "Melbourne-Auction-Result-"+datetime.now().strftime("%Y%m%d%H%M%S")+".pdf"
urllib.urlretrieve ("http://domainmastheads.homepriceguide.com.au/saturday_auction_results/Melbourne.pdf",saveFileName )
saveFileName = "Brisbane-Auction-Result-"+datetime.now().strftime("%Y%m%d%H%M%S")+".pdf"
urllib.urlretrieve ("http://domainmastheads.homepriceguide.com.au/saturday_auction_results/Brisbane.pdf",saveFileName )
#saveFileName = "Sydney-Domain-Auction-Result-"+datetime.now().strftime("%Y%m%d%H%M%S")+".pdf"
#urllib.urlretrieve ("http://www.domain.com.au/apm/saturday_auction_results/Sydney_Domain.pdf",saveFileName )

Sunday, November 1, 2015

exercises in python

---join
In [4]: a
Out[4]: ['1', '2', '3', '4']

In [6]: ',tail'.join(a)
Out[6]: '1,tail2,tail3,tail4'

--dictionary
In [20]: dict
Out[20]: {'H1': 'H1 UL1 [%]', 'H2': 'H2 UL1 [%]'}

In [21]: for i in dict: print dict[i]
H2 UL1 [%]
H1 UL1 [%]


 ---type
>> type([]) is list
True
>>> type({}) is dict
True
>>> type('') is str
True
>>> type(0) is int
True
>>> type({})

>>> type([])

>> type([]) is list
True
>>> type({}) is dict
True
>>> type('') is str
True
>>> type(0) is int
True
>>> type({})

>>> type([])


---utilities
In [3]: print int("0x3cf",0)  python hex to int

Thursday, October 29, 2015

Sample Python Codes plot value with date time axis in matplotlib



[1] stackoverflow.com/ plotting-time-in-python-with-matplotlib



#!/usr/bin/env python

import matplotlib.pyplot as plt
import datetime



ax = tuple([datetime.datetime(2015, 10, 27, 17, 17, sec) for sec in range(1,10)])
print ax

ay = tuple(range(1,10))

plt.plot(ax,ay)
# Beautify the display format
plt.gcf().autofmt_xdate()
plt.show()


When doing enough zoom in, it will display in macro seconds resolution. When zooming out enough,it will display dates.