· 5 years ago · Sep 21, 2020, 02:46 PM
1import tweepy
2import requests
3import os
4
5# https://851028.smushcdn.com/1862890/wp-content/uploads/2020/06/facts-about-mountains-840x490.jpg?lossy=1&strip=1&webp=1
6# first link
7
8# http://www.inspire-travel.com/wp-content/uploads/2020/01/Waterfalls-1050x748.jpg
9# second link
10
11#Authenticate (first oauth is equal to api key, second api key secret, first in access token = access token, second is access token secret)
12auth = tweepy.OAuthHandler("YLp44QDJH8WzsNlmCznhcXmAT", "aPoYZIj0zLjtt6yaqLKvfJbGkqadetQwcGkducbqqyQF4nrNNJ")
13auth.set_access_token("885771179356819457-L2pq3Za7fU8EDjDSjKGPAhI3UCkPi4N", "dcypB2cSnAh6f3caE8Hf9PA9EUQxps8iT5ON8uxoANuNx")
14
15api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
16
17
18def send_Tweet(message):
19 api.update_status(message)
20
21def send_Image_Tweet(url, message):
22 filename = "temp.jpg"
23 request = requests.get(url, stream=True)
24 if request.status_code == 200:
25 with open(filename, 'wb') as image:
26 for chunk in request:
27 image.write(chunk)
28 api.update_with_media(filename, status=message)
29 os.remove(filename)
30 else:
31 print("Error! Unable to download image.")
32
33def main_Menu():
34 print("Hello, it is me - Your Command Line Twitter!")
35 print("What do you want to do?")
36 print("1: Send an Tweet")
37 print("2: Send an Tweet with an Image")
38 print("3: Get your timeline (20 latest messages on your main twitter screen)")
39 x = input()
40 return x
41
42x = main_Menu()
43
44if x == "1":
45 print("Selected: 1: Send an Tweet")
46 print("What message do you want to send?")
47 message = input()
48 print("Ready to send your message, : " + message + " ?")
49 print("Y/N")
50 userChoice1 = input()
51 if userChoice1 == "Y":
52 send_Tweet(message)
53 elif userChoice1 == "N":
54 print("Alright. Going back to the menu.")
55 main_Menu()
56 else:
57 print("Wrong Choice! Going back to the menu.")
58 main_Menu()
59elif x == "2":
60 print("Selected 2: Send an Tweet with an Image")
61 print("What image do you want to send? (Direct URL link)")
62 url = input()
63 print("Are you sure this is an direct link?")
64 print("Y/N")
65 userChoice1 = input()
66 if userChoice1 == "Y":
67 print("Alright, got it. Now what message do you want to add to the image tweet?")
68 urlMessage = input()
69 print(urlMessage + " Is that the message you want to add?")
70 userChoice2 = input()
71 if userChoice2 == "Y":
72 print(url + "Is the image link, and " + urlMessage + "Is the message you want to send, do you want to send?")
73 print("Y/N")
74 userChoice3 = input()
75 if userChoice3 == "Y":
76 send_Image_Tweet(url, urlMessage)
77 elif userChoice3 == "N":
78 print("Alright. Going back to the menu.")
79 main_Menu()
80 else:
81 print("Wrong Choice! Going back to the menu.")
82 main_Menu()
83 elif userChoice2 == "N":
84 print("Alright. Going back to the menu.")
85 main_Menu()
86 else:
87 print("Wrong Choice! Going back to the menu.")
88 main_Menu()
89 elif userChoice1 == "N":
90 print("Alright. Going back to the menu.")
91 main_Menu()
92 else:
93 print("Wrong Choice! Going back to the menu.")
94 main_Menu()
95
96# made by clima :D