以下是我的 Python 脚本,它将喜欢的推文中的链接添加到 Pocket:
from dotenv import load_dotenv
load_dotenv()
import os
import re
import tweepy
from pocket import Pocket
#Twitter keys
consumer_key = os.environ.get('API_key')
consumer_secret = os.environ.get('API_secretkey')
#Pocket keys
p_consumer_key = os.environ.get('Pocket_consumer_key')
p_access_token = os.environ.get('Pocket_access_token')
#authenticate and call twitter api
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth, parser=tweepy.parsers.JSONParser())
p = Pocket(consumer_key=p_consumer_key, access_token=p_access_token)
#gets JSON of liked tweets
fav = api.favorites('importhuman', count=100, tweet_mode='extended')
links = []
for status in fav:
url_list = status['entities']['urls']
if url_list != []:
for item in url_list:
link = item['expanded_url']
if link not in links:
if re.search("//twitter.com/", link) is None:
links.append(link)
p.add(link)
我正在尝试自动化此脚本以每 5 分钟运行一次,为此我正在尝试设计一个 GitHub 工作流程,但到目前为止它还没有工作。
name: run-five-minutes
on:
schedule:
- cron: '*/5 * * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: '3.x'
- run: pip install -r requirements.txt
env:
API_key: ${{ secrets.API_KEY }}
API_secretkey: ${{ secrets.API_SECRETKEY }}
Pocket_consumer_key: ${{ secrets.POCKET_CONSUMER_KEY }}
Pocket_access_token: ${{ secrets.POCKET_ACCESS_TOKEN }}
- run: python3 app.py
该requirements.txt
文件有python-dotenv、tweepy 和pocket。任何帮助,将不胜感激。