Skip to content

Instantly share code, notes, and snippets.

@lynn
Created May 30, 2017 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lynn/c483707623a5cb1fabdaf6e574a87e66 to your computer and use it in GitHub Desktop.
Save lynn/c483707623a5cb1fabdaf6e574a87e66 to your computer and use it in GitHub Desktop.
Update your Twitter profile color in a day-night gradient cycle
from datetime import datetime, timedelta
from PIL import Image
import twitter
def clock_fraction():
'Return time since midnight rescaled to [0, 1); e.g. 0.5 is noon.'
now = datetime.now()
midnight = now.replace(hour=0, minute=0, second=0, microsecond=0)
return (now - midnight) / timedelta(days=1)
# Log in to Twitter. .twitter is four lines:
# Consumer Key, Consumer Secret, Access Token Key, Access Token Secret
with open('/home/lynn/.twitter') as f:
api = twitter.Api(*f.read().split())
# Index into the gradient and update the profile color. gradient.png is a 24x1 image.
colors = list(Image.open('gradient.png').getdata())
i = int(clock_fraction() * len(colors))
api.UpdateProfile(profile_link_color='%02X%02X%02X' % colors[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment