-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetMenu.py
More file actions
42 lines (30 loc) · 1.13 KB
/
getMenu.py
File metadata and controls
42 lines (30 loc) · 1.13 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
def getMenu():
from urllib import response
import tweepy
import requests
import os
from dotenv import load_dotenv
load_dotenv()
# 認証に必要なキーとトークン
API_KEY = os.environ['API_KEY']
API_SECRET = os.environ['API_SECRET']
ACCESS_TOKEN = os.environ['ACCESS_TOKEN']
ACCESS_TOKEN_SECRET = os.environ['ACCESS_TOKEN_SECRET']
# APIの認証
auth = tweepy.OAuthHandler(API_KEY, API_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
for tweet in api.search_tweets(q='"今週のメニュー" from:@CISTcafe'):
imageUrl = tweet.extended_entities['media'][0]['media_url']
response = requests.get(imageUrl)
image = response.content
fileName = 'menu'
fileNameJpg = fileName + '.jpg'
with open(fileNameJpg, "wb")as f:
f.write(image)
# with open(fileName + '.pdf', "wb")as f:
# f.write(img2pdf.convert(fileNameJpg))
print(imageUrl)
print(tweet.text)
print(tweet.created_at)
print("=============================")