#!/usr/bin/env python # -*- coding: utf-8 -*- #twitter one liner http://commandline.org.uk/python/scripting-twitter-with-python/ # remove html tags http://love-python.blogspot.com/2008/07/strip-html-tags-using-python.html import urllib import re import time USERNAME='username' PASSWORD='password' def remove_html_tags(data): p = re.compile(r'<.*?>| ') return p.sub('', data) def getToday(): eshop = urllib.urlopen("http://www.eshop.gr") for e in eshop: if e.find("today") > 0: string = remove_html_tags(e) string = unicode(string, 'iso8859-7').encode('utf-8') string = string.strip() string = time.strftime("%d") + "/" + time.strftime("%m") + " " + string if string.split()[3] == '--': # den exi giorti kalitera allakse to keimeno string = "%s Καμία γιορτή για σήμερα %s" % (string[:5], string[40:]) return string def truncate(string,target): if len(string) > target: return string[:(target-3)] + "..." else: return string def squawk(username,password,message): """Simple post-to-twitter function""" message = truncate(message,140) # trim message data = urllib.urlencode({"status" : message}) #identi.ca res = urllib.urlopen("http://%s:%s@identi.ca/api/statuses/update.xml" % (username,password), data) #twitter res = urllib.urlopen("http://%s:%s@twitter.com/statuses/update.xml" % (username,password), data) return res if __name__== "__main__": # print getToday() r = squawk(USERNAME, PASSWORD, getToday())