Information obtained from tweet_id (Python)

This is the second article. I will write about Twitter like this.

Completion code

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. bandicam 2020-02-08 01-14-41-754.jpg

Is it really right! About that bandicam 2020-02-08 00-50-10-563.jpg https://www.slideshare.net/pfi/id-15755280 Since it matches here, you should be able to get it firmly.

Explanation Break down the Tweet id into binary numbers and pad it with 0s to the left with 63 digits. tttttttttttttttttttttttttttttttttttttttttdddddwwwwwssssssssssss 000001111100001011010111001111011011110110000100111000000000000![bandicam 2020-02-08 01-09-57-277.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/522233/0a3264a3-5a60-2fcb-af6f-f19c51bc3705.jpeg)

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

Information obtained from tweet_id (Python)
[Python] Scraping lens information from Kakaku.com
Collecting information from Twitter with Python (Twitter API)
sql from python
MeCab from Python
Collecting information from Twitter with Python (Environment construction)
Get BTC / JPY board information from Python --bitflyer
Use thingsspeak from python
Touch MySQL from Python 3
Operate Filemaker from Python
Use fluentd from python
Changes from Python 2 to Python 3.0
Python from or import
Use MySQL from Python
Run python from excel
Install python from source
Execute command from Python
Operate neutron from Python!
Use MySQL from Python
Operate LXC from Python
Manipulate riak from python
Force Python from Fortran
Use BigQuery from python.
Execute command from python
[Python] Read From Stdin
Use mecab-ipadic-neologd from python
Collecting information from Twitter with Python (morphological analysis with MeCab)
Deep Python learned from DEAP
Grammar features added from Python3.6
Cheating from PHP to Python
OCR from PDF in Python
Run illustrator script from python
Use MySQL from Anaconda (python)
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
Study from Python Hour4: Object-oriented ②
Query Athena from Lambda Python
Access Oracle DB from Python
Study from Python Hour3: Functions
Start / stop GCE from python
Stop Omxplayer from Python code
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
Install pyenv from Homebrew, install Python from pyenv
Study from Python Hour4: Object-oriented ①
Python naming convention (from PEP8)
Collecting information from Twitter with Python (MySQL and Python work together)
Plot geographic information in Python
With skype, notify with skype from python!
Use e-Stat API from Python
Get Alembic information with Python
Register redmine issue from Python
Python: Extract file information from shared drive with Google Drive API
Call Matlab from Python to optimize
Execute Python script from batch file
Call a Python function from p5.js.
Python: Exclude tags from html data
Use Stanford Core NLP from Python
Try IAM Database Authentication from Python
Call C from Python with DragonFFI
Touch a Python object from Elixir
Hit treasure data from Python Pandas