Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import pathlib, urllib, time, os, datetime
try:
import tweepy
except:
print("You don't have tweepy installed")
raise SystemExit
directory = "/home/fantoro"
key = ""
secret = ""
last_tweet_id = ""
def get_mins_to_nearest_post():
dt = datetime.datetime.now()
if(dt.minute >= 50):
return 60-dt.minute
nearest_minute = dt.minute
while (nearest_minute%10) != 0:
nearest_minute += 1
return nearest_minute-dt.minute
def on_status(status,ltid):
if(ltid == status.id):
return ltid
if (status.user.id == "2907774137"):
return ltid
print("New Archillect tweet")
tweet_entities = status.entities
if not ("media" in tweet_entities):
return ltid
print("Tweet contains media")
media_entity = tweet_entities["media"][0]
if not (media_entity["type"] == "photo"):
return ltid
print("Included media is a photo, downloading")
response = urllib.request.urlopen(media_entity["media_url"])
data = response.read()
f = open("%s/wallpaper.new" % directory,"wb")
f.write(data)
f.close()
os.system('''qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript '
var allDesktops = desktops();
print (allDesktops);
for (i=0;i<allDesktops.length;i++) {{
d = allDesktops[i];
d.wallpaperPlugin = "org.kde.image";
d.currentConfigGroup = Array("Wallpaper",
"org.kde.image",
"General");
d.writeConfig("Image", "file://%s/wallpaper.new")
}}
'
''' % directory)
os.replace("%s/wallpaper.new" % directory,"%s/wallpaper" % directory)
os.system('''qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript '
var allDesktops = desktops();
print (allDesktops);
for (i=0;i<allDesktops.length;i++) {{
d = allDesktops[i];
d.wallpaperPlugin = "org.kde.image";
d.currentConfigGroup = Array("Wallpaper",
"org.kde.image",
"General");
d.writeConfig("Image", "file://%s/wallpaper")
}}
'
''' % directory)
print("Done")
return status.id
print("Authenticating")
try:
auth = tweepy.AppAuthHandler(key,secret)
except Exception as e:
print(e)
raise SystemExit
print("Creating API object")
api = tweepy.API(auth)
while True:
print("Fetching latest tweet")
tweets = api.user_timeline(id="2907774137",count=1)
last_tweet_id = on_status(tweets[0], last_tweet_id)
mins = get_mins_to_nearest_post()
print(mins)
time.sleep(mins*60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.