· 6 years ago · Nov 21, 2019, 04:52 AM
1import twitter, time # twitter api
2from newsapi import NewsApiClient # google news api
3from youtube_api import YouTubeDataAPI # youtube api
4import praw # for reddit api
5
6
7def ravisiswaliya_bot():
8 api = twitter.Api(consumer_key="ZIt3V2zNCiBCNPNEhhvKkXLzg",
9 consumer_secret="KX2yV6plxB3T6jnHafCRkWeWhxxcBh8w00hpssLyQeyuY0WWQF",
10 access_token_key="1304214913-MOOQQRkmN9sFa0uvhYgtIBCfxbW0tO6DIcIR0Ym",
11 access_token_secret="zm0JnmotEk1oUc7yY5AZ36R2GUH9Qph5DezydCWeKbfbM")
12
13 results = api.GetSearch('vuejs+OR+python+OR+django+OR+machinelearning+OR+datascience+OR+artificialIntelligence',
14 count=100)
15 s = 0
16 success = 0
17 fail = 0
18 for result in results:
19 s = s + 1
20 print('Tweeted: ', s)
21 import time
22 time.sleep(6)
23 try:
24 ptweet = api.PostRetweet(result.id_str) # retweeting twitter tweets
25 success = success + 1
26
27 except Exception as e:
28 print(e)
29 fail = fail + 1
30
31 print('Success', success)
32 print('Fail', fail)
33
34 print('-----------------------')
35 print('Total Tweeted: ', s)
36 print('Total Success', success)
37 print('Toatal Fail', fail)
38
39
40def post_google_news():
41 newsapi = NewsApiClient(api_key='6760c2444156485f99422d210577ecba') # google search api
42 all_articles = newsapi.get_everything(q='Data Science vs Big Data', language='en') # getting news content
43
44 api = twitter.Api(consumer_key="ZIt3V2zNCiBCNPNEhhvKkXLzg",
45 consumer_secret="KX2yV6plxB3T6jnHafCRkWeWhxxcBh8w00hpssLyQeyuY0WWQF",
46 access_token_key="1304214913-MOOQQRkmN9sFa0uvhYgtIBCfxbW0tO6DIcIR0Ym",
47 access_token_secret="zm0JnmotEk1oUc7yY5AZ36R2GUH9Qph5DezydCWeKbfbM")
48
49 cnt = 0
50 for a in all_articles['articles']:
51 t_data = str(a['title'] + ' \n' + a['url'])
52 api.PostUpdate(status=t_data) # posting google news to twitter
53 cnt = cnt + 1
54 print(t_data)
55 print(cnt, 'Tweeted done!')
56 print('---------------------------------------------------------------')
57 time.sleep(5)
58
59
60def youtube_bot():
61 api = twitter.Api(consumer_key="ZIt3V2zNCiBCNPNEhhvKkXLzg",
62 consumer_secret="KX2yV6plxB3T6jnHafCRkWeWhxxcBh8w00hpssLyQeyuY0WWQF",
63 access_token_key="1304214913-MOOQQRkmN9sFa0uvhYgtIBCfxbW0tO6DIcIR0Ym",
64 access_token_secret="zm0JnmotEk1oUc7yY5AZ36R2GUH9Qph5DezydCWeKbfbM")
65 api_key = "AIzaSyANsP6att16TWBrFcdYJp3AUD85FFjiMQM" # youtube data api key
66 yt = YouTubeDataAPI(api_key)
67 result = yt.search('vue js vs react js', max_results=15) # calling search api
68
69
70 for r in result:
71 t_data = r['video_title'] + '\n' + "https://www.youtube.com/watch?v=" + r['video_id']
72 print(t_data)
73 print("https://www.youtube.com/watch?v=" + r['video_id'])
74 api.PostUpdate(status=t_data) # posting youtube video to twitter
75 time.sleep(6)
76 #aa = yt.get_video_metadata("_uQrJ0TkZlc") # single video details
77 #print(aa)
78 print('-----------------------------------------------------')
79
80
81def reddit_bot():
82 reddit = praw.Reddit(client_id = "uAPssjaWmdpcFg",
83 client_secret = "VlKIqUCPQWHhXzthX_3wOj2zAQ0"
84 )
85
86ravisiswaliya_bot()
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121"""
122# google new content
123{'source': {
124 'id': None, 'name':
125 'Adafruit.com'},
126 'author': 'Becca',
127 'title': 'Streamlit for interactive Machine Learning Apps #MachineLearning #DataScience #Python #MLtools @streamlit @myelbows',
128 'description': 'Last month Streamlit launched their front end tool for machine learning teams. The project is open-source and easy to get up and running. Streamlit fills the need for tooling somewhere between JuPyter notebooks and consumer applications that can be written in…',
129 'url': 'https://blog.adafruit.com/2019/11/01/streamlit-for-interactive-machine-learning-apps-machinelearning-datascience-python-mltools-streamlit-myelbows/',
130 'urlToImage': 'https://cdn-blog.adafruit.com/uploads/2019/11/Screen-Shot-2019-11-01-at-10.00.14-AM.png',
131 'publishedAt': '2019-11-01T18:07:15Z',
132 'content': 'November 1, 2019 AT 2:07 pm\r\nStreamlit for interactive Machine Learning Apps #MachineLearning #DataScience #Python #MLtools @streamlit @myelbows\r\nExample of a Streamlit slider widget.\r\nLast month Streamlitlaunched their front end tool for machine learning tea… [+3542 chars]'}
133
134# youtube data API
135
136{'video_id': '_uQrJ0TkZlc',
137 'channel_title': 'Programming with Mosh',
138 'channel_id': 'UCWv7vMbMWH4-V0ZXdmDpPBA',
139 'video_publish_date': datetime.datetime(2019, 2, 18, 15, 0, 8),
140 'video_title': 'Python Tutorial for Beginners [Full Course] 2019',
141 'video_description': 'Python tutorial for beginners - Learn Python for machine learning and web development. Get My Complete Python Programming Course with a 90% Discount ...',
142 'video_category': None,
143 'video_thumbnail': 'https://i.ytimg.com/vi/_uQrJ0TkZlc/hqdefault.jpg',
144 'collection_date': datetime.datetime(2019, 11, 19, 13, 56, 42, 405239)}
145
146# youtube video metadata api
147{
148 'video_id': '_uQrJ0TkZlc',
149 'channel_title': 'Programming with Mosh',
150 'channel_id': 'UCWv7vMbMWH4-V0ZXdmDpPBA',
151 'video_publish_date': datetime.datetime(2019, 2, 18, 15, 0, 8),
152 'video_title': 'Python Tutorial for Beginners [Full Course] 2019',
153 'video_description': 'Python tutorial for beginners - Learn Python for machine learning and web development.',
154 'video_category': '27',
155 'video_view_count': '5672364',
156 'video_comment_count': '13462',
157 'video_like_count': '202710',
158 'video_dislike_count': '1464',
159 'video_thumbnail': 'https://i.ytimg.com/vi/_uQrJ0TkZlc/hqdefault.jpg',
160 'video_tags': 'python tutorial|python|python for beginners|python tutorial for beginners|learn python|python crash course|python 2019|python tutorial for beginners full|python (programming language)|python basics|python course|python from scratch|python full course|python language|python programming|python programming language|python programming tutorial|getting started with python|learn python programming|web development|mosh hamedani|machine learning',
161 'collection_date': datetime.datetime(2019, 11, 19, 18, 20, 40, 594572)
162}
163
164"""