Created
July 6, 2021 11:35
-
-
Save old-school-devv/9ee70ae3a51b0ae4fa417e8a2cafe7bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Config | |
require "twitter" | |
config = { | |
consumer_key: "Der Twitter-Consumer-Key", | |
consumer_secret: "Das Twitter-Consumer-Secret", | |
access_token: "Das Access-Token", | |
access_token_secret: "Das Access-Token-Secret" | |
} | |
twitta = Twitter::REST::Client.new(config) | |
twarchiv = "data/tweet.js" | |
stopwords = ["old-school.dev","borussia"] | |
rcount = 0 | |
kill = false | |
if ARGV | |
if ARGV[0]=="kill" | |
kill = true | |
puts "Parameter kill wurde gesetzt, es wird nun geloescht!" | |
sleep 7 | |
end | |
end | |
# Verarbeitung | |
JSON.parse(File.read(twarchiv).gsub("window.YTD.tweet.part0 = ","")).each do |tw| | |
# Wenn wir Tweets mit Links auf eine bestimmte URL aufheben wollen, | |
# muessen wir die richtige URL auslesen, der Tweettext enthält | |
# nur den gekuerzten Link auf t.co. | |
tw_url = '' | |
tw["tweet"].each do |el| | |
if el[0]=="entities" | |
el[1].each do |ent| | |
if ent[0]=="urls" | |
if ent[1].size > 0 | |
tw_url = ent[1][0]["expanded_url"] | |
end | |
end | |
end | |
end | |
end | |
full_text = "#{tw["tweet"]["full_text"].to_s} #{tw_url}".downcase | |
# Ermitteln ob der Tweet eine Reply ist, Replies werden immer geloescht! | |
is_reply = false | |
if tw["tweet"]["in_reply_to_status_id_str"] | |
is_reply = true | |
end | |
# Entscheiden ob man den Tweet loeschen moechte | |
delete_it = false | |
if is_reply | |
# Reply (Antworten auf andere Tweets) immer loeschen! | |
delete_it = true | |
else | |
# Schauen ob eines der stopwords enthalten ist | |
unless stopwords.any? {|s| full_text.include?(s.downcase)} | |
delete_it = true | |
end | |
end | |
# Loeschen | |
if delete_it | |
begin | |
puts "#{rcount}: zwitschiloesch #{tw["tweet"]["id_str"]}" | |
twitta.destroy_tweet tw["tweet"]["id_str"].to_s if kill | |
rescue Twitter::Error::NotFound => e | |
puts " => ERR not found" | |
rescue Twitter::Error::Forbidden => e | |
puts " => ERR forbidden: #{e}" | |
end | |
else | |
puts "#{rcount}: keep #{tw["tweet"]["id_str"]}" | |
end | |
rcount += 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Beschreibung / Description (in german): old-school.dev