Last active
August 29, 2015 14:20
-
-
Save tobocop2/0ff78a80fedde4d0a186 to your computer and use it in GitHub Desktop.
Thanks
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 config import * | |
import arrow | |
import subprocess | |
import facebook | |
'''Comment and like all posts''' | |
def thank_friends(): | |
gist = 'https://gist.github.com/T-G-P/0ff78a80fedde4d0a186' | |
message = """ | |
Laziness got the best of me so I am having my server send thanks and likes for me. | |
I know you probably think this is weird... automation can be scary sometimes. | |
Anyway, I know this is a bit impersonal and I apologize. | |
To make up for it, let me share the mediocre specs of this virtual machine with you:\n | |
%s\n%s\n\n For those interested in this script: %s """ % (get_cpu_info(), get_rel_info(), gist) | |
try: | |
graph=facebook.GraphAPI(access_token=access_token) | |
feed = graph.request('%s/feed' % facebook_id, args = {'limit': 666}) | |
post_ids = list(set(get_post_ids(feed))) | |
for post_id in post_ids: | |
graph.put_comment(object_id=post_id, message=message) | |
graph.put_like(object_id=post_id) | |
set_post_time(feed) | |
except facebook.GraphAPIError as err: | |
print err.message | |
'''Get relevant posts in array form''' | |
def get_post_ids(feed): | |
post_ids = [] | |
for comment in feed['data']: | |
created_time = arrow.get(comment['created_time']).datetime | |
unix_time = int(created_time.strftime('%s')) | |
if unix_time <= int(poll_time): | |
return post_ids | |
post_ids.append(comment['id']) | |
return post_ids | |
'''Parse OS info to a string''' | |
def get_rel_info(): | |
command = subprocess.Popen( | |
['cat', '/etc/lsb-release'], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE | |
) | |
lsb, err = command.communicate() | |
command = subprocess.Popen( | |
['cat', '/etc/os-release'], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE | |
) | |
os, err = command.communicate() | |
return lsb+os | |
'''Parse cpu info to a string''' | |
def get_cpu_info(): | |
command = subprocess.Popen( | |
['cat', '/proc/cpuinfo'], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.PIPE | |
) | |
out, err = command.communicate() | |
return out | |
'''Update the last polling time to be the latest post in the feed''' | |
def set_post_time(feed): | |
latest_post = feed['data'][0] | |
created_time = arrow.get(latest_post['created_time']).datetime | |
unix_time = int(created_time.strftime('%s')) | |
if unix_time < 1430089200: | |
return | |
with open(last_poll_path,'w') as f: | |
f.write(str(unix_time)) | |
if __name__ == "__main__": | |
thank_friends() |
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
app_id ='' | |
app_secret = '' | |
facebook_id = '' | |
token_path = '' | |
last_poll = '' | |
with open(token_path,'r') as f: access_token = f.read() | |
with open(last_poll,'r') as f: poll_time = int(f.read()) |
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
#Cron runs every half hour on April 27th. | |
*/30 * 27-28 04 * <path to python> <path to script> |
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
<poll time stored here> |
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
<access token goes here> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment