Skip to content

Commit

Permalink
fully works, checks latest mention
Browse files Browse the repository at this point in the history
  • Loading branch information
supthunder authored Jan 18, 2017
1 parent 63244c7 commit fdaf8c3
Showing 1 changed file with 52 additions and 7 deletions.
59 changes: 52 additions & 7 deletions matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,69 @@
import requests
import re
import json
import re
import urllib.request
from time import gmtime, strftime
import tweepy
from tokens import *
import os

# setup twitter
auth = tweepy.OAuthHandler(C_KEY, C_SECRET)
auth.set_access_token(A_TOKEN, A_TOKEN_SECRET)
api = tweepy.API(auth)
username = ""
tweetId = ""

def tweet(imageName):
tweet = "@"+username+"\n"
tweet += "Converted Image:\n"
tweet += strftime("%Y-%m-%d %H:%M:%S", gmtime())
print(tweet)
api.update_with_media(imageName,status=tweet,in_reply_to_status_id=tweetId)
os.remove(imageName)


def getImageName(imageLink):
nameRegex = re.compile('[^/]*$')
imageName = "./"
imageName += re.search(nameRegex, imageLink).group(0)
return imageName

def getMentions():
imageUrl = ""
mentions = api.mentions_timeline(count=1)
global username
global tweetId
for mention in mentions:
imageUrl = mention.entities['media'][0]['media_url']
username = mention.user.screen_name
tweetId = mention.id

imageName = getImageName(imageUrl)
urllib.request.urlretrieve(imageUrl, imageName)
return imageName



def uploadImage(url, image):

def uploadImage(url):
file = {'image': open('test.png','rb')}
file = {'image': open(image,'rb')}
r = requests.post(url, files=file)
soup = BeautifulSoup(r.text,"html.parser")

imageLink = (soup.find(bgcolor='black')).find('img')['src']
nameRegex = re.compile('[^/]*$')
imageName = "./"
imageName += re.search(nameRegex, imageLink).group(0)
# nameRegex = re.compile('[^/]*$')
# imageName = "./"


# imageName += re.search(nameRegex, imageLink).group(0)
imageName = getImageName(imageLink)
urllib.request.urlretrieve(imageLink, imageName)
tweet(imageName)

def main():
url = "http://www.text-image.com/convert/matrix.cgi"
uploadImage(url)
image = getMentions()
uploadImage(url,image)
os.remove(image)
main()

0 comments on commit fdaf8c3

Please sign in to comment.