This repository has been archived by the owner on Nov 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
62 lines (46 loc) · 2.04 KB
/
test.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
# -*- coding: utf-8 -*-
#
# Please refer to AUTHORS.md for a complete list of Copyright holders.
# Copyright (C) 2020-2022 Luis Alejandro Martínez Faneyth.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import os
import time
import tempfile
from urllib.request import urlopen
from tweepy import OAuth1UserHandler, API
consumer_key = os.environ.get('TWITTER_CONSUMER_KEY')
consumer_secret = os.environ.get('TWITTER_CONSUMER_SECRET')
oauth_token = os.environ.get('TWITTER_OAUTH_TOKEN')
oauth_secret = os.environ.get('TWITTER_OAUTH_SECRET')
status_text = os.environ.get('STATUS_TEXT')
status_image_url_1 = os.environ.get('STATUS_IMAGE_URL_1')
status_image_url_2 = os.environ.get('STATUS_IMAGE_URL_2')
status_image_url_3 = os.environ.get('STATUS_IMAGE_URL_3')
status_image_url_4 = os.environ.get('STATUS_IMAGE_URL_4')
media_ids = []
auth = OAuth1UserHandler(consumer_key, consumer_secret,
oauth_token, oauth_secret)
api = API(auth, wait_on_rate_limit=True)
for imgurl in [status_image_url_1,
status_image_url_2,
status_image_url_3,
status_image_url_4]:
if not imgurl:
continue
_, tmpimg = tempfile.mkstemp(prefix='status-image-url-', suffix='.bin')
with open(tmpimg, 'wb') as i:
i.write(urlopen(imgurl).read())
media = api.media_upload(tmpimg)
media_ids.append(media.media_id)
tweet = api.update_status(status_text, media_ids=media_ids)
time.sleep(10)
api.destroy_status(tweet.id)