Created
May 30, 2017 19:34
-
-
Save lynn/c483707623a5cb1fabdaf6e574a87e66 to your computer and use it in GitHub Desktop.
Update your Twitter profile color in a day-night gradient cycle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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