Created
March 17, 2017 00:55
-
-
Save 33mhz/69ca1a6a01093754aeb59f6bcb4236b5 to your computer and use it in GitHub Desktop.
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
# Author: @33MHz | |
# 2017-03-04 hackday | |
# Polls, printing to USB receipt printer | |
from pnutpy import api | |
import subprocess | |
from shlex import quote | |
api.add_authorization_token('TOKEN HERE') | |
# get since_id from file | |
try: | |
f = open("FOLDER LOCATION/since_id","r") | |
except: | |
f = open("FOLDER LOCATION/since_id","w") | |
since_id = f.read() | |
f.close() | |
if not since_id or since_id == '': | |
since_id = 1 | |
# get tags | |
posts = api.posts_with_hashtag('pnutprinter',since_id=since_id,include_deleted=0) | |
# save since_id | |
f = open("FOLDER LOCATION/since_id","w") | |
try: | |
posts[0][0].id | |
except: | |
f.write(since_id) | |
else: | |
f.write(str(posts[0][0].id)) | |
f.close() | |
# repost them | |
for post in reversed(posts[0]): | |
cmd = "echo "+ str(post.id) +" @"+post.user.username+": "+ quote(post.content.text) +" | lpr -P receipt" | |
try: | |
# repost | |
api.repost_post(post.id) | |
subprocess.check_output(cmd, shell=True) | |
except: | |
print('error reposting or printing') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment