Fleet bietet die Möglichkeit, Twitter zu nutzen und auf beispiellose Weise auf Twitter zu kommunizieren. Der auf Fleet geteilte Inhalt verschwindet nach 24 Stunden, sodass Sie Ihre Gedanken und Gefühle von Depressionen teilen können. Sie können Ihre vorübergehenden persönlichen Gedanken mit Ihren Followern teilen, ohne dass andere allgemeine Benutzer darauf reagieren. Flottenersteller können auf ihre Flotte klicken und auf den gelesenen Text unten tippen, um zu sehen, wer ihre Flotte angesehen hat, einschließlich Konten, die Tweets privat halten.
DeleteNoRtFavReplyTweets
| lambda.yml
| README.md
|
\---code
DeleteNoRtFavReplyTweets.py
Cloudformation
AAWSTemplateFormatVersion: '2010-09-09'
# Twitter API Key
Parameters:
ConsumerKey:
Type: String
NoEcho: true
ConsumerSecret:
Type: String
NoEcho: true
AccessKey:
Type: String
NoEcho: true
AccessSecret:
Type: String
NoEcho: true
Resources:
# Lambda
Lambda:
Type: 'AWS::Lambda::Function'
Properties:
Code: code
Environment:
Variables:
ConsumerKeyVar: !Ref ConsumerKey
ConsumerSecretVar: !Ref ConsumerSecret
AccessKeyVar: !Ref AccessKey
AccessSecretVar: !Ref AccessSecret
Description: NoRtFavReplyTweetDelete
FunctionName: NoRtFavReplyTweetDelete
Handler: noRtFavTweetDelete.lambda_handler
MemorySize: 128
Role: !Sub
- arn:aws:iam::${AWS::AccountId}:role/${Domain}
- { Domain: !Ref LambdaRole }
Runtime: python3.8
Timeout: 180
# CloudWatchEvents Rule
Rule:
Type: 'AWS::Events::Rule'
Properties:
Description: NoRtFavReplyTweetDeleteRule
Name: NoRtFavReplyTweetDeleteRule
ScheduleExpression: 'cron(0 17 * * ? *)' #2 Uhr nachts
State: ENABLED
Targets:
- Arn: !GetAtt Lambda.Arn
Id: lambda
# Lambda IAM Role
LambdaRole:
Type: 'AWS::IAM::Role'
Properties:
RoleName: deleteTweetRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- 'sts:AssumeRole'
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
# CloudWatchEvents Lambda excute enable
LambdaEvent:
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:InvokeFunction'
FunctionName: !Ref Lambda
Principal: 'events.amazonaws.com'
SourceArn: !GetAtt Rule.Arn
Python
import tweepy
import os
# API Key
consumer_key = os.environ['ConsumerKeyVar']
consumer_secret = os.environ['ConsumerSecretVar']
access_key = os.environ['AccessKeyVar']
access_secret = os.environ['AccessSecretVar']
# Tweepy Auth
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth, wait_on_rate_limit = True)
noFavRtTweet = []
mentionTweet = []
noDeleteTweet = []
def lambda_handler(event, context):
# No Favorite No RT Tweet
print("==========No Favorite No RT Tweet==========")
for tweet in tweepy.Cursor(api.user_timeline,exclude_replies = True).items():
if tweet.favorite_count == 0 and tweet.retweet_count == 0: #Ändern Sie entsprechend der Anzahl der Favoriten
print(tweet.id,tweet.created_at,tweet.text.replace('\n',''))
noFavRtTweet.append(tweet.id)
# Reply Tweet
print("==========Reply Tweet==========")
for mentions in tweepy.Cursor(api.mentions_timeline).items():
print(mentions.id,mentions.created_at,mentions.text.replace('\n',''))
mentionTweet.append(mentions.in_reply_to_status_id)
print("==========No Favorite No RT Reply Tweet==========")
# No Favorite No RT Reply Tweet
for tweet in noFavRtTweet:
for reptw in mentionTweet:
if tweet == reptw:
print(api.get_status(tweet).id,api.get_status(tweet).created_at,api.get_status(tweet).text.replace('\n',''))
noDeleteTweet.append(tweet)
# Extraction Delete Tweet
print("==========Extraction Delete tweet==========")
perfectList = set(noFavRtTweet) ^ set(noDeleteTweet)
print(list(perfectList))
# Delete Tweet
print("==========delete tweet==========")
for deltw in perfectList:
print(api.get_status(deltw).id,api.get_status(deltw).created_at,api.get_status(deltw).text)
api.destroy_status(deltw)
--Tweepy ist ein externes Modul, daher ist es enthalten.
pip install tweepy --target ./code
--Paket und Transfer zu S3
aws cloudformation package --s3-bucket $YourBucketName `
--template-file lambda.yml `
--output-template-file lambda-packaged.yml
aws cloudformation deploy `
--template-file lambda-packaged.yml `
--stack-name $YourStackName `
--parameter-overrides AccessSecret=$YourAccessSecret `
ConsumerKey=$YourConsumerKey `
ConsumerSecret=$YourConsumerSecret `
AccessKey=$YourAccessKey `
--capabilities CAPABILITY_NAMED_IAM
https://github.com/trysaildaisuki/DeleteNoReactionReply
Recommended Posts