├── README.md └── quinetweet.py /README.md: -------------------------------------------------------------------------------- 1 | # quinetweet 2 | Code to generate a tweet that quotes itself—specifically this one: https://twitter.com/quinetweet/status/1309951041321013248 3 | Write up at: https://oisinmoran.com/quinetweet 4 | -------------------------------------------------------------------------------- /quinetweet.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | import subprocess 3 | import json 4 | 5 | OFFSET = 1288834974657 6 | TIME_DIFF = 359 7 | MACHINE_ID = 377 8 | N = 10 9 | 10 | def tweet_id_from_timestamp(utcdttime): 11 | tstamp = utcdttime.timestamp() 12 | tid = int(tstamp * 1000) - OFFSET 13 | return tid << 22 14 | 15 | def tweet_id_to_parts(tid): 16 | timestamp = tid >> 22 17 | machine_id = (tid >> 12) & (2**10-1) 18 | seq_no = tid & (2**12-1) 19 | return timestamp, machine_id, seq_no 20 | 21 | def compare_ids(guessed_id, real_id): 22 | guessed_ts, guessed_mid, guessed_sno = tweet_id_to_parts(guessed_id) 23 | real_ts, real_mid, real_sno = tweet_id_to_parts(real_id) 24 | ms = guessed_ts - real_ts 25 | mid_diff = guessed_mid - real_mid 26 | sno_diff = guessed_sno - real_sno 27 | return ms, mid_diff, sno_diff 28 | 29 | def guess_tweet_id(time_diff=0, machine_id=0): 30 | tid = tweet_id_from_timestamp(datetime.now()) 31 | tid += machine_id << 12 32 | tid += time_diff << 22 33 | return tid 34 | 35 | def guess(): 36 | for _ in range(N): 37 | guessed_id = guess_tweet_id(TIME_DIFF, MACHINE_ID) 38 | command = f"twurl -d 'status=https://twitter.com/quinetweet/status/{guessed_id}' /1.1/statuses/update.json" 39 | op = subprocess.check_output(command, shell=True) 40 | actual_id = json.loads(op.decode())["id"] 41 | print(actual_id) 42 | time, mid, sno = compare_ids(guessed_id, actual_id) 43 | print(time, mid, sno) 44 | if (time, mid, sno) == (0, 0, 0): 45 | print("Success") 46 | break 47 | 48 | guess() 49 | --------------------------------------------------------------------------------