3 ms·
It seems like more and more links to Twitter being submitted to HN. This is inconvenient for me as I do not use Twitter's GUI. I do not like the way Twitter u
by 1vuio0pswjnm7 5y ago
It seems like more and more links to Twitter being submitted to HN. This is inconvenient for me as I do not use Twitter's GUI. I do not like the way Twitter uses Javascript and tries to force users to enable it.
Here is a temporary solution to I am using to fetch the JSON from the command line and make simple HTML. I did try Nitter but found that sometimes instances were exceeding rate limits.
json_reformat is from https://github.com/lloyd/yajl https://github.com/lloyd/yajl
this uses stunnel and nc but can easily be adapted to use openssl, bssl, haproxy, or whatever other ssl solution you prefer
example usage - read twitter.com/foone
1.sh foone > 1.json
1.sh < 1.json > 1.htm
firefox ./1.htm
#!/bin/sh
case $# in :)
;;0) # make simple html;
sed -n /{\"data\"/p|json_reformat|tr -cd '\12\40-\176'|sed -n -e 's/ *//' -e 's/\\n/ /g' \
-e '/created_at/p;/sation_id_str/p;/full_text/p'|grep -B2 full_text \
|sed 's,https://[^ \"]*,<a href=&>&</a>,g;s/\",$/&<br>/g;s/^--/&<br>/'
;;1) # fetch json;
M="GET"; V="HTTP/1.1";H="host: twitter.com";I="104.244.42.129:443";C="connection: close";
A="authorization: Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA";
P1="/i/api/graphql/Vf8si2dfZ1zmah8ePYPjDQ/UserByScreenNameWithoutResults?variables=%7B%22screen_name%22%3A%22$1%22%2C%22withHighlightedLabel%22%3Atrue%7D";
S1(){ printf "%s\n%s\n%s\n%s\n%s\n" "pid=$HOME/1.pid" "[ $$ ]" "accept=127.0.0.7:80" "client=yes" "connect=$I"|stunnel -fd 0;};
S2(){ kill -9 $(cat $HOME/1.pid);};
N(){ nc -n 127.7 80;};
S1;x=$(printf "%s %s %s\r\n%s\r\n%s\r\n\r\n" "$M" "/" "$V" "$H" "$C"|N|grep -o "gt=[^;]*"|sed 's/gt=//');t="x-guest-token: $x";
y=$(printf "%s %s %s\r\n%s\r\n%s\r\n%s\r\n%s\r\n\r\n" "$M" "$P1" "$V" "$H" "$A" "$t" "$C"|N|grep -o "rest_id\":\"[^\"]*"|sed 's/.*\"//');
p2="/i/api/graphql/Bn2jPG0Cy8VAOakAoyV_kA/UserTweets?variables=%7B%22userId%22%3A%22$y%22%2C%22count%22%3A500%2C%22withHighlightedLabel%22%3Atrue%2C%22withTweetQuoteCount%22%3Atrue%2C%22includePromotedContent%22%3Atrue%2C%22withTweetResult%22%3Afalse%2C%22withUserResults%22%3Afalse%2C%22withVoice%22%3Afalse%2C%22withNonLegacyCard%22%3Atrue%2C%22withBirdwatchPivots%22%3Afalse%7D";
printf "%s %s %s\r\n%s\r\n%s\r\n%s\r\n%s\r\n\r\n" "$M" "$p2" "$V" "$H" "$t" "$A" "$C"|N;S2;
esac
- dTal 5y agoJesus. Did it run first time?
- nexuist 5y agoNot sure if you've censored that auth token preemptively, but if not, you should consider it :)
- 1vuio0pswjnm7 5y agoWithout logging in to Twitter, if you look at the HTTP and HTML sent from twitter.com when you make a request (I try to log all traffic to/from my computers), you will see the exact same token. There's nothing "secret" about this header. Thus, there's nothing to censor. I have seen it in other people's code as well. It gets sent to everyone who visits twitter.com.
- nexuist 5y agoAh okay. Weird design choice since it doesn't seem to be authenticating anything, but glad that you thought about it!
- 1vuio0pswjnm7 5y agoImproved the simple HTML output. No need for json_reformat. WIP. # 1.sh username > 1.json # 1.sh < 1.json > 1.htm # or # 1.sh username|1.sh > 1.htm # firefox ./1.htm (zoom in) case $# in :) ;;1) public_ip=104.244.42.129:443; public_host="Host: twitter.com"; public_token="Authorization: Bearer AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"; printf "%s\n%s\n%s\n%s\n%s\n" "pid=$HOME/1.pid" "[ $$ ]" "client=yes" "accept=127.0.0.7:80" "connect=$public_ip"|stunnel -fd 0; x=$(printf "GET / HTTP/1.1\r\n%s\r\nConnection: close\r\n\r\n" "$public_host"|nc -vvn 127.7 80|grep -o "gt=[^;]*"|sed 's/gt=//'); echo gt $x >/dev/stderr;y=$(printf "GET %s HTTP/1.1\r\n%s\r\n%s\r\n%s\r\nConnection: close\r\n\r\n" \ "/i/api/graphql/Vf8si2dfZ1zmah8ePYPjDQ/UserByScreenNameWithoutResults?variables=%7B%22screen_name%22%3A%22$1%22%2C%22withHighlightedLabel%22%3Atrue%7D" \ "$public_host" "$public_token" "X-Guest-Token: $x"|nc -vvn 127.7 80|grep -o "rest_id\":\"[^\"]*"|sed 's/.*\"//'); echo rest_id $y >/dev/stderr;printf "GET %s HTTP/1.1\r\n%s\r\n%s\r\n%s\r\nConnection: close\r\n\r\n" \ "/i/api/graphql/Bn2jPG0Cy8VAOakAoyV_kA/UserTweets?variables=%7B%22userId%22%3A%22$y%22%2C%22count%22%3A500%2C%22withHighlightedLabel%22%3Atrue%2C%22withTweetQuoteCount%22%3Atrue%2C%22includePromotedContent%22%3Afalse%2C%22withTweetResult%22%3Afalse%2C%22withUserResults%22%3Afalse%2C%22withVoice%22%3Afalse%2C%22withNonLegacyCard%22%3Atrue%2C%22withBirdwatchPivots%22%3Afalse%7D" "$public_host" "$public_token" "X-Guest-Token: $x"|nc -vvn 127.7 80 kill -9 $(cat "$HOME"/1.pid) ;;0) x=$(echo x|exec tr x '\34'); sed -e 's/\\"/\"/g;s/\\n/ /g' -e "s/\"legacy\":/$x/g" \ |exec tr -cd '\34\11\12\40-\176'|exec tr -d '\12'|exec tr '\34' '\12' \ |exec grep -Eo '("created_at":"[^"]*)|("conversation_id_str":"[^"]*)|("url":"[^"]*)|("expanded_url":"[^"]*)|("full_text":"[^"]*)' \ |exec sed '/"created_at":"/s//<br>/; /"conversation_id_str":"/s///;/"url":"/{s///;s/"//g; s/.*/<a href=&>&<\/a>/;}; /"expanded_url":"/{s///;s/.*/<a href=&>&<\/a>/;};/"full_text":"/s///; s| https://[^ ]*| <a href=&>&</a> |g;s/> />/g; /^RT @/s/$/ (RETWEET)/;s/$/<br>/;s/\\u.\{4\}//g'|uniq esac