Bladeren bron

wip

master
Asherah Connor 4 maanden geleden
commit
b8629f9faa
3 gewijzigde bestanden met toevoegingen van 98 en 0 verwijderingen
  1. +4
    -0
      .gitignore
  2. +3
    -0
      Gemfile
  3. +91
    -0
      poputweets

+ 4
- 0
.gitignore Bestand weergeven

@@ -0,0 +1,4 @@
Gemfile.lock
.bundle
tweet.js
smol.js

+ 3
- 0
Gemfile Bestand weergeven

@@ -0,0 +1,3 @@
source "https://rubygems.org"



+ 91
- 0
poputweets Bestand weergeven

@@ -0,0 +1,91 @@
#!/usr/bin/env ruby

require 'json'
require 'pp'
require 'time'

ME = "67204542"

class Tweet
def initialize(hash)
@data = {}
%w(favorite_count id_str retweet_count created_at full_text
in_reply_to_status_id_str in_reply_to_user_id_str
in_reply_to_screen_name).each do |key|
@data[key] = hash.delete(key)
end

if hash.length > 0
raise "unhandled data remains: #{hash.inspect}"
end
end

def favs
@data["favorite_count"].to_i
end

def rts
@data["retweet_count"].to_i
end

def id
@data["id_str"]
end

def created_at
Time.parse(@data["created_at"])
end

def text
@data["full_text"]
end

def in_reply_to
status_id = @data["in_reply_to_status_id_str"]
user_id = @data["in_reply_to_user_id_str"]
screen_name = @data["in_reply_to_screen_name"]
screen_name && {
status_id: status_id,
user_id: user_id,
screen_name: screen_name,
}
end

def inspect
"<Tweet at #{created_at} (#{favs}❤️ #{rts}🔄) #{text.inspect}>"
end

def root?
!in_reply_to
end
end

data = File.read(ENV["POPUTWEET_JS"] || "tweet.js")
tweets = JSON.parse(data[data.index("[")..-1])
tweets.map! do |tweet|
tweet = tweet["tweet"]
%w(possibly_sensitive entities source display_text_range lang
extended_entities retweeted favorited truncated
id in_reply_to_user_id in_reply_to_status_id).each do |key|
tweet.delete(key)
end
Tweet.new(tweet)
end

tweets.reject! do |tweet|
tweet.text.start_with?("RT @") ||
begin
in_reply_to = tweet.in_reply_to
in_reply_to && in_reply_to[:user_id] != ME
end
end

tweets_by_id = {}
tweets.each do |tweet|
tweets_by_id[tweet.id] = tweet
end

pp tweets_by_id

pp tweets_by_id.first
pp tweets_by_id.first[1].root?

Laden…
Annuleren
Opslaan