#! /usr/bin/python # -*- coding: utf-8 -*- import random import tweepy import os from datetime import datetime from pytz import timezone def do_the_magic(): print "start" # twitter app config consumer_key = "key" consumer_secret = "secret" access_token = "token" access_token_secret = "token-secret" number_of_images_available = 3134 # hand-shaking auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth) print "twitter api:" + str(api) # choosing the file to upload image_number_to_upload = str(random.randint(1, number_of_images_available)).zfill(6) random_choice = "./"+image_number_to_upload+".jpg" print "losuje obrazek" # determining timezones and building the status content current_status = "" time_format = "%H:%M" timezonelist = { "London": "Europe/London", "Warsaw": "Europe/Warsaw", "New York": "America/New_York", "Sydney": "Australia/Sydney" } for city, zone in sorted(timezonelist.items()): current_status += city + ": " + (datetime.now(timezone(zone))).strftime(time_format) + "\n" print "ogarniam godzine" # figuring out the time and building the string while True: if (os.path.isfile(random_choice)): api.update_with_media(random_choice, current_status) print "wrzucilem status" break else: image_number_to_upload = str(random.randint(1, number_of_images_available)).zfill(5) random_choice = "/home/lwoo/itscatoclock/" + image_number_to_upload + ".jpg" print "jeszcze raz losuje" pass def main(): do_the_magic() if __name__ == "__main__": main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question