Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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)
# print
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
You can’t perform that action at this time.