i_delete_my_tweets 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a35b1623c288676e843c2fe7502c6493eaee928106f6bfc055f7ea58f0e7dce4
4
- data.tar.gz: a17670785c43a2fe7286cded54798a7526e6a983bae60ea93acd0b5e3816ef8a
3
+ metadata.gz: be66c7e72077b06365cabdc0076dfed3a0cc84fe7cba83def5f0d3cf7b276e0a
4
+ data.tar.gz: 7ecec19ba9016ef147caa5aa23806502c90906ba6de02310c88ed25e5d390e1a
5
5
  SHA512:
6
- metadata.gz: 2c2a1130f2b64bc07bdef9dd116b9b86b249351854c95e46f3205c044bcec13693209cabaf86020fcd882588b9ba1815709cefb2cff14eb6b2d1b741c92390f3
7
- data.tar.gz: e783246fe0d21e6c1c971042b0f1eed0e7cd73c409817c6f8fc27847fdbdbd36e264e3865f67259531a503354996e0b7fb624b3875b67110b36d056ae2abad64
6
+ metadata.gz: 4cfcaab2091d0b8b29aa1994f766e82760ca035d9ef25f61ca7ccdb0288c90aa2d0f6be6c8c452ecb96414857ce6309634cb3b8a8e508fc83957f01767d8d504
7
+ data.tar.gz: 66d0e753c0c5f53ee21d0e78623fff14896ba9f7220be74756bf404e9008a19fe559686f451baea22dbe1c06738acc11223e291a4f04498ba7580b269e8d6535
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # I Delete My Tweets
2
2
 
3
+ <img width="800" alt="Screen Shot 2022-05-11 at 19 04 53" src="https://user-images.githubusercontent.com/12278/167955371-a24ec8e6-bd9a-4014-bc25-9fb9e3cb21ce.png">
4
+
3
5
  A **CLI** (as in Command Line Interface) to delete your tweets based on faves, RTs, and time.
4
6
 
5
7
  There are some services out there with a friendly web interface, but this is not one of them.
@@ -13,7 +15,13 @@ Called with `--dry-run=false`, there is no way to revoke tweet deletion. They ar
13
15
 
14
16
  This tool won't delete all of your tweets in one fell swoop; it is more of a way to delete your old tweets from time to time. The [Twitter API rate limits](https://developer.twitter.com/en/docs/twitter-api/rate-limits) are relatively complicated, and I don't even wanna go there, but if you do intend on deleting all of your tweets, you can do it with this CLI and some perseverance. I did delete more than 100k of mine by using this script every day for a couple of weeks. The more tweets you delete, the fewer of them you have, and with time the rate limits won't be that much of a problem.
15
17
 
16
- I Delete My Tweets (IDMT) can delete your tweets by fetching them via API using an APP you will have to set up yourself. Still, it can also delete tweets from an CSV (comma-separated file) that you can generate from the archive you can request from twitter.com by going to Settings and privacy > Your Account > Download an archive of your data. It is out of the scope of this CLI to generate the CSV (at the moment) but [there are scripts out there](https://gist.github.com/jessefogarty/b0f2d4ea6bdd770e5e9e94d54154c751) that can do this for you.
18
+ I Delete My Tweets (IDMT) can delete your tweets by fetching them via API using an APP you will have to set up yourself. Still, it can also delete tweets from an CSV (comma-separated file) that you can generate from the archive you can request from twitter.com by going to Settings and privacy > Your Account > Download an archive of your data. Once you get your zipped archive from Twitter, unzip it, and find the `tweet.js` file.
19
+
20
+ IDMT can convert that into a CSV file with:
21
+
22
+ ```sh
23
+ $ i_delete_my_tweets convert to_csv path_to_tweet.js
24
+ ```
17
25
 
18
26
  > TIP: You can find an example of the CSV header in the project's root folder.
19
27
 
@@ -10,6 +10,7 @@ require 'twitter'
10
10
  require 'oauth'
11
11
  require 'active_support/all'
12
12
  require 'terminal-table'
13
+ require 'progress'
13
14
  require 'byebug'
14
15
  require 'i_delete_my_tweets'
15
16
 
@@ -7,6 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.add_dependency 'csv', '~> 3.0.9'
8
8
  spec.add_dependency 'dotenv', '~> 2.7.6'
9
9
  spec.add_dependency 'oauth', '>= 0.5.5'
10
+ spec.add_dependency 'progress', '~> 3.6.0'
10
11
  spec.add_dependency 'terminal-table', '~> 3.0.2'
11
12
  spec.add_dependency 'thor', '~> 1.2.1'
12
13
  spec.add_dependency 'twitter', '~> 7.0.0'
@@ -1,3 +1,5 @@
1
+ require 'ostruct'
2
+
1
3
  module IDeleteMyTweets
2
4
  class Api
3
5
  include Presenter
@@ -27,22 +29,19 @@ module IDeleteMyTweets
27
29
  end
28
30
 
29
31
  def traverse_csv!
30
- CSV.foreach(config.path_to_csv, headers: true) do |tweet|
31
- if to_time(tweet["timestamp"]) >= config.older_than
32
- self.skipped_count += 1
33
- next
34
- end
35
-
36
- tw_data = fetch_tweet(tweet["tweet_id"])
37
- next if tw_data.nil?
38
-
39
- if can_be_destroyed?(tw_data)
40
- destroy_with_retry(tw_data)
32
+ CSV.foreach(config.path_to_csv, headers: true) do |row|
33
+ tweet = csv_row_to_struct(row)
34
+ if can_be_destroyed?(tweet)
35
+ destroy_with_retry(tweet)
41
36
  sleep a_bit
42
37
  else
43
38
  self.skipped_count += 1
44
39
  end
45
40
  end
41
+ rescue IOError
42
+ do_log(" 💥 Oops, there was a connection error! ", color: :red)
43
+ ensure
44
+ do_log summary delete_count, skipped_count, not_found_count, dry_run
46
45
  end
47
46
 
48
47
  def client
@@ -141,5 +140,15 @@ module IDeleteMyTweets
141
140
  rescue HTTP::ConnectionError
142
141
  do_log(" 💥 Oops, there was a connection error fetching your tweets! ", color: :red)
143
142
  end
143
+
144
+ def csv_row_to_struct(row)
145
+ Struct.new(:id, :favorite_count,
146
+ :retweet_count, :created_at,
147
+ :text, keyword_init: true).new(id: row["tweet_id"],
148
+ text: row["text"],
149
+ created_at: to_date(row["created_at"]),
150
+ favorite_count: row["favorite_count"],
151
+ retweet_count: row["retweet_count"])
152
+ end
144
153
  end
145
154
  end
@@ -1,6 +1,45 @@
1
1
  require 'thor'
2
2
 
3
3
  module IDeleteMyTweets
4
+ class CommandConvert < Thor
5
+ class_option :dry_run, type: :boolean, default: true
6
+
7
+ include Presenter
8
+
9
+ KEYS = %w(id retweet_count favorite_count created_at full_text).freeze
10
+ HEADERS = %w(tweet_id retweet_count favorite_count created_at text).freeze
11
+
12
+ desc "to_csv", "Converts the tweet.js archive to csv"
13
+ def to_csv(path_to_tweets_js)
14
+ if js_to_json(path_to_tweets_js)
15
+ save_to_csv(path_to_tweets_js)
16
+ say set_color " ✅ Success: << #{path_to_tweets_js} >> was converted to << converted_tweets_js.csv >>!", :white, :on_green, :bold
17
+ else
18
+ say set_color " 🚫 Something went wrong with sed. Make sure you have it available in your terminal. ", :white, :on_red, :bold
19
+ end
20
+ rescue StandardError => e
21
+ say_error e.message
22
+ end
23
+
24
+ desc "js_to_json", "Converts the tweet.js to a valid JSON"
25
+ def js_to_json(path_to_tweets_js)
26
+ system(%(sed -i"" -e "s/window.YTD.tweet.part0 = //g" #{path_to_tweets_js}))
27
+ rescue StandardError => e
28
+ say_error e.message
29
+ end
30
+
31
+ private
32
+
33
+ def save_to_csv(path_to_tweets_js)
34
+ CSV.open("converted_tweets_js.csv", "w") do |csv|
35
+ csv << HEADERS
36
+ JSON.parse(File.read(path_to_tweets_js)).with_progress('Converting your tweets') do |hash|
37
+ csv << hash["tweet"].fetch_values(*KEYS)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
4
43
  class CommandDelete < Thor
5
44
  class_option :dry_run, type: :boolean, default: true
6
45
 
@@ -134,5 +173,8 @@ module IDeleteMyTweets
134
173
 
135
174
  desc "config command ...ARGS", "Configures the Twitter app credentials"
136
175
  subcommand "config", CommandConfig
176
+
177
+ desc "convert command ...ARGS", "Converts the tweets.js archive to CSV"
178
+ subcommand "convert", CommandConvert
137
179
  end
138
180
  end
@@ -50,7 +50,7 @@ module IDeleteMyTweets
50
50
  text.gsub(/^(.{40,}?).*$/m, '\1...')
51
51
  end
52
52
 
53
- def to_time(timestamp)
53
+ def to_date(timestamp)
54
54
  Date.parse timestamp
55
55
  end
56
56
 
data/tweets.csv CHANGED
@@ -1 +1 @@
1
- "tweet_id","in_reply_to_status_id","in_reply_to_user_id","timestamp","source","text","retweeted_status_id","retweeted_status_user_id","retweeted_status_timestamp","expanded_urls"
1
+ tweet_id,retweet_count,favorite_count,created_at,text
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i_delete_my_tweets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - "'Fabio"
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-05-11 00:00:00.000000000 Z
13
+ date: 2022-06-08 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -68,6 +68,20 @@ dependencies:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: 0.5.5
71
+ - !ruby/object:Gem::Dependency
72
+ name: progress
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: 3.6.0
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: 3.6.0
71
85
  - !ruby/object:Gem::Dependency
72
86
  name: terminal-table
73
87
  requirement: !ruby/object:Gem::Requirement