-
Notifications
You must be signed in to change notification settings - Fork 4
/
dress.py
executable file
·71 lines (52 loc) · 2.04 KB
/
dress.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import math
import random
import twitter
import cairocffi as cairo
from PIL import Image
import struct
from auth import *
api = twitter.Api(consumer_key=Akey,consumer_secret=Askey,access_token_key = Atoken,access_token_secret = Astoken)
adjective = open("adjectives.txt","r")
color = open("rgb.txt","r")
adjectives = adjective.read().splitlines()
colors = color.read().splitlines()
adjective1 = adjectives[random.randint(0,len(adjectives)-1)]
adjective2 = adjectives[random.randint(0,len(adjectives)-1)]
adjective3 = adjectives[random.randint(0,len(adjectives)-1)]
color1 = colors[random.randint(0,len(colors)-1)].split(",")
color2 = colors[random.randint(0,len(colors)-1)].split(",")
color3 = colors[random.randint(0,len(colors)-1)].split(",")
string1 = adjective1 + " " + color1[0]
string2 = adjective2 + " " + color2[0]
string3 = adjective3 + " " + color3[0]
rgbstr1 = struct.unpack("BBB",color1[1][1:].decode("hex")) + (1,)
rgbstr2 = struct.unpack("BBB",color2[1][1:].decode("hex")) + (1,)
rgbstr3 = struct.unpack("BBB",color3[1][1:].decode("hex")) + (1,)
WIDTH,HEIGHT = 512,512
schemepng = cairo.ImageSurface(cairo.FORMAT_ARGB32,WIDTH,HEIGHT)
ctx = cairo.Context(schemepng)
portion = random.randint(3,6)
rotate = random.randint(0,3)
ctx.rectangle(0,0,WIDTH/portion,HEIGHT)
ctx.set_source_rgba(rgbstr1[0]/255.0,rgbstr1[1]/255.0,rgbstr1[2]/255.0,rgbstr1[3])
ctx.fill()
ctx.rectangle(WIDTH/portion,0,WIDTH,HEIGHT)
ctx.set_source_rgba(rgbstr2[0]/255.0,rgbstr2[1]/255.0,rgbstr2[2]/255.0,rgbstr2[3])
ctx.fill()
ctx.rectangle(WIDTH/(portion-1),0,WIDTH,HEIGHT)
ctx.set_source_rgba(rgbstr3[0]/255.0,rgbstr3[1]/255.0,rgbstr3[2]/255.0,rgbstr3[3])
ctx.fill()
schemepng.write_to_png("test.png")
rotated = Image.open("test.png").rotate(rotate*90)
rotated.save("test.png")
tweet = ""
if rotate == 2 or rotate == 1:
tweet = string3 + "\n" + string2 + "\n" + string1
tweet.replace("\n","")
print tweet
else:
tweet = string1 + "\n" + string2 + "\n" + string3
tweet.replace("\n","")
print tweet
finalimage = open("test.png","r")
api.PostMedia(tweet,finalimage)