Last active
April 22, 2017 20:52
-
-
Save vim13/08f8889176349625e37fa93533c1929b 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
#!/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('><p>(.*?)</p></content>', str(a)).group(1) | |
if re.search('<a href="(.*?)"', txt): | |
a = re.search('(.*?)<a href="', txt).group(1) | |
b = re.search('<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 = {'&':'&', '<':'<', '>':'>', ' ':' '} | |
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