Skip to content

Instantly share code, notes, and snippets.

@pkoch
Created January 19, 2017 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkoch/c33176541cb149d5c8aa8e172caa98a6 to your computer and use it in GitHub Desktop.
Save pkoch/c33176541cb149d5c8aa8e172caa98a6 to your computer and use it in GitHub Desktop.
import json
def slurp_entries(file_name):
return [json.loads(l) for l in open(file_name).readlines()]
def truque(file_name):
"""
Identify users that retweet stuff within one second of its publishing date
and do no other actions.
file_name: The input
"""
alibied = set()
culprits = set()
tape = []
tweets_in_tape = set()
for entry in slurp_entries(file_name):
while tape[0]['timestamp'] < entry['timestamp'] - 1000:
t = tape.pop(0)
tweets_in_tape.remove(t['id'])
tape.append(entry)
id_ = entry['id']
tweets_in_tape.add(id_)
user = entry['user']
if (
entry['action'] == 'retweet'
and id_ in tweets_in_tape
and user not in alibied
):
culprits.add(user)
else:
alibied.add(user)
culprits.remove(user)
return culprits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment