Oct
13
2008
Quotation Crawler към мобилен
at
10:05 by
nofearinc
Category: techies
import sys
import urllib
import httplib
from xml.etree import ElementTree
quotes = []
countryCode = 359 # country code
operatorCode = 881 # operator code
telphone = 987654 # tel phone
#
def initQuotes():
#Brainyquote Quote of the day feed
tree = ElementTree.parse(urllib.urlopen('http://feeds.feedburner.com/brainyquote/QUOTEBR'))
for item in tree.findall('//item'):
quotes.append({
'title': item[0].text,
'quote': item[1].text
})
def lookupSendQuote(index):
smsportal = httplib.HTTPConnection('smsbg.net')
aQuote = quotes[index] #The index selects one of the 4 quotations in the RSS
params = urllib.urlencode({'MN1': countryCode, 'MN2': operatorCode, 'MN3': telphone, 'FROM': aQuote['title'],
'SM': aQuote['quote']})
params = params + '&num=0&sbm=%C8%E7%EF%F0%E0%F9%E0%ED%E5'
print 'params: ' + params
headers = {'Host': 'smsbg.net', 'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14',
'Accept': 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Keep-Alive': '300', 'Connection': 'keep-alive', 'Referer': 'http://smsbg.net/', 'Content-Type': 'application/x-www-form-urlencoded'}
smsportal.request('get', 'http://smsbg.net/', '', headers)
response = smsportal.getresponse()
cookieHeader = response.getheader('Set-Cookie', '')
print 'cookie: ' + cookieHeader
headers = {'Host': 'smsbg.net', 'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14',
'Accept': 'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
'Keep-Alive': '300', 'Connection': 'keep-alive', 'Referer': 'http://smsbg.net/', 'Content-Type': 'application/x-www-form-urlencoded',
'Cookie': cookieHeader}
smsportal.request('post', '/sms.php?' + params, '', headers)
response = smsportal.getresponse()
print response.status, response.reason
data = response.read()
#print data
smsportal.close()
initQuotes()
# a check for console argument, otherwise sends the second quote by default (well, why not?)
if(len(sys.argv) > 1):
lookupSendQuote(int(sys.argv[1]))
else:
lookupSendQuote(1)
Махнах личния си телефон, за да не получавам излишен спам Безподобния пост.
Related posts brought to you by Yet Another Related Posts Plugin.


















Спасибо классная статья
[...] Един от първите ми постове в блога бе за скрипт, който агрегира дневните цитати от сайт и ги праща като SMS. Повечето сайтове онлайн са [...]