56
edits
No edit summary  | 
				 (Midtermbot)  | 
				||
| Line 186: | Line 186: | ||
     saveFrame("robot_const_###.png")  |      saveFrame("robot_const_###.png")  | ||
</pre>  | |||
==== Midtermbot ====  | |||
<pre style="font-size:smaller" >  | |||
"""  | |||
midtermbot.py  | |||
"""  | |||
###Import###  | |||
#Import Modules for Project  | |||
from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageColor  | |||
import tweepy  | |||
import time  | |||
import random  | |||
import requests  | |||
from io import BytesIO  | |||
#Import aus Dateien  | |||
from twitterkeys import *  | |||
from textposts import text  | |||
from imagefuncs import blur, emboss, edges, invert, transpose  | |||
##############  | |||
###Programm###  | |||
##############  | |||
###Twitter connect###  | |||
#TwitterPassVariable for Test without posting on Twitter  | |||
#True = Post on Twitter / False = just open Image and show text local  | |||
check = False  | |||
#Define TwitterKeys to variables  | |||
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)  | |||
auth.secure = True  | |||
auth.set_access_token(access_token, access_token_secret)  | |||
api = tweepy.API(auth)  | |||
#Find Images and URL in Account on Twitter  | |||
timeline = api.user_timeline(screen_name = "C64_Bot")   | |||
for tweet in timeline:   | |||
   for media in tweet.entities.get("media",[{}]):  | |||
    if media.get("type",None) == "photo":  | |||
        url = media["media_url"]  | |||
###Load Image from URL###  | |||
#"http://maui.hawaii.edu/tlc/wp-content/uploads/sites/53/2013/11/testing.jpg"  | |||
response = requests.get(url)  | |||
image = Image.open(BytesIO(response.content))  | |||
#Test Bild laden  | |||
#image = Image.open("test.png")  | |||
#Liste der verschiedenen Funktionen erstellen  | |||
functions_list = [blur, emboss, edges, invert, transpose]  | |||
#Mainfunction  | |||
if __name__ == "__main__":      | |||
    #Random eine Funktion aufrufen  | |||
    imagefunc = random.choice(functions_list)  | |||
    #Random Funktion anwenden  | |||
    image = imagefunc(image)  | |||
    #2.Runde Random Filter anwenden  | |||
    #Random eine Funktion aufrufen  | |||
    imagefunc = random.choice(functions_list)  | |||
    #Random Funktion anwenden  | |||
    image = imagefunc(image)  | |||
    if check == True:  | |||
        filename = "final.png"  | |||
        image.save(filename)  | |||
        api.update_with_media(filename,text)    | |||
    else:  | |||
        image.show()  | |||
        print(text)  | |||
</pre>  | |||
<pre style="font-size:smaller" >  | |||
"""  | |||
imagefuncs.py  | |||
"""  | |||
from PIL import Image, ImageDraw, ImageFont, ImageFilter, ImageColor, ImageEnhance  | |||
#verschiedene Bildbearbeitungfunktionen  | |||
#Bild blur  | |||
def blur (image):  | |||
    return image.filter(ImageFilter.BLUR)  | |||
def emboss (image):  | |||
    return image.filter(ImageFilter.EMBOSS)  | |||
def edges (image):  | |||
    return image.filter(ImageFilter.FIND_EDGES)  | |||
def transpose(image):  | |||
    return image.transpose(Image.FLIP_LEFT_RIGHT)  | |||
def invert(image):  | |||
    return image.point(lambda x: 255-x)  | |||
</pre>  | |||
<pre style="font-size:smaller" >  | |||
"""  | |||
textposts.py  | |||
"""  | |||
#Import Modules for Project  | |||
import random  | |||
#Verschiedene Texte die gepostet werden können  | |||
a="Yeah, a new Image is Ready"  | |||
b="I'am an artist.What you think about?"  | |||
c="Uh, which great Effekt"  | |||
d="Nice"  | |||
e="Thats what I do"  | |||
f="Mhmmm, what you mean? Is this art?"  | |||
g="Yes I post"  | |||
h="I should do an exhibition whith this works."  | |||
i="Tell me what you think about."  | |||
j="This is my job! Post Pictures..."  | |||
k="Funky..."  | |||
#Liste mit allen Textinhalten erstellen  | |||
text_list = [a, b, c, d, e, f, g, h, i, j, k]  | |||
#Zufällige auswahl eines Inhalts  | |||
text = random.choice(text_list)  | |||
</pre>  | </pre>  | ||
edits