This is the second article. I will write about Twitter like this.
tweetid.py
from datetime import datetime
tweet_id = 279622981959970816
print("tweet_id =",tweet_id)
tweet_raw = format(tweet_id,'016b')
print ("tweet_raw =",tweet_raw)
tweet_raw=format(int(tweet_raw), '064')[1:]
sequence = tweet_raw[51:]
worker_id = tweet_raw[46:-12]
datacenter_id = tweet_raw[41:-17]
machine_id = datacenter_id + worker_id
timestamp_id = tweet_raw[:-22]
seq=int(sequence,2)
work=int(worker_id,2)
data=int(datacenter_id,2)
machine=int(machine_id,2)
timestamp=int(timestamp_id,2)
unixtime = (timestamp + 1288834974657)/1000
time = datetime.fromtimestamp(unixtime)
print("sequence =",seq)
print("worker_id =",work)
print("datacenter_id =",data)
print("machine_id =",machine)
print("timestamp_id =",timestamp)
print("unixtime=",unixtime)
print(time)
It will be printed like this.
Is it really right! About that https://www.slideshare.net/pfi/id-15755280 Since it matches here, you should be able to get it firmly.
t = timestamp (fixed UNIX time) d = datacenter_id (literally) w = worker_id (literally) dw = machine_id (literally) s = seqence (serial number) It is like that.
I want a function that gets only time! In that case, please click here
gettime.py
def get_time(id):
two_raw=format(id,'016b').zfill(64)
unixtime = int(two_raw[:-22],2) + 1288834974657
ime = datetime.datetime.fromtimestamp(unixtime/1000)
return ime
fixed phrase I'm always on Twitter (@ kenkensz9) so if you have any questions I hope you like it!
Recommended Posts