-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGettingData.py
More file actions
88 lines (59 loc) · 1.83 KB
/
GettingData.py
File metadata and controls
88 lines (59 loc) · 1.83 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
import requests
import numpy as np
import cv2
import urllib.request
from DominantColors import DominantColors
import urllib
import tweepy
import time
# Twitter bot initialization
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
#variables
api_key = '?API_KEY_HERE'
url = 'https://api.themoviedb.org/3/movie/'
urls = []
start = 0
end = 100
for i in range(start,end):
try:
mov_num = str(i)
JSONcontent = requests.get(url + mov_num + api_key)
response = JSONcontent.json()
base_url = 'https://image.tmdb.org/t/p/w500'
img_url = response['poster_path']
image_url = base_url + img_url
urls.append(image_url)
print(urls)
except:
print("pass")
pass
def url_to_image(url):
resp = urllib.request.urlopen(url)
image = np.array(bytearray(resp.read()))
image = cv2.imdecode(image, cv2.IMREAD_COLOR)
return image
for url in urls:
image = url_to_image(url)
# cv2.imshow("Image", image)
cv2.imwrite("1.jpg", image)
img = '1.jpg'
clusters = 6
dc = DominantColors(img, clusters)
dc.dominantColors()
color = dc.plotHistogram()
# cv2.imshow("img", color)
numpy_vertical = np.vstack((color, image))
# cv2.imshow('main_image', numpy_vertical)
cv2.imwrite("main.jpg", numpy_vertical)
final = "main.jpg"
# cv2.waitKey()
#Twitter Bot
time.sleep(60)
api.update_with_media(final, "Follow my code! - https://github.com/DataStroke99/MovieColorPalette-TwitterBot "
+ " #cinema #movie #moviepalette #palette #MovieColor #color #art #computerscience")