Skip to content

Instantly share code, notes, and snippets.

@vim13
Last active April 22, 2017 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vim13/08f8889176349625e37fa93533c1929b to your computer and use it in GitHub Desktop.
Save vim13/08f8889176349625e37fa93533c1929b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
import time
import urllib2
import tweepy
import BeautifulSoup
import xml.sax.saxutils
atom = urllib2.urlopen('https://mstdn.sszk.sk/@sszk.atom').read()
soup = BeautifulSoup.BeautifulSoup(atom)
entry = soup.findAll('entry')
opened_file = open('/home/mastodon/python/tweet/entry.txt', 'r')
logs = []
for line in opened_file:
logs.append(line[:-1])
opened_file.close()
content = []
for a in entry:
if re.search("New status by sszk", str(a)):
txt = re.search('>&lt;p&gt;(.*?)&lt;/p&gt;</content>', str(a)).group(1)
if re.search('&lt;a href="(.*?)"', txt):
a = re.search('(.*?)&lt;a href="', txt).group(1)
b = re.search('&lt;a href="(.*?)"', txt).group(1)
txt = a + b
content.append(txt)
new = []
for y in content:
if y not in logs:
new.append(y)
if new:
opend_file = open('/home/mastodon/python/tweet/entry.txt', 'w')
for x in content:
opend_file.write(str(x)+'\n')
opend_file.close()
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
ACCESS_TOKEN = ''
ACCESS_SECRET = ''
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)
entities = {'&amp;':'&', '&lt;':'<', '&gt;':'>', '&nbsp;':' '}
new.reverse()
for z in new:
api.update_status(xml.sax.saxutils.unescape(z, entities))
time.sleep(10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment