惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Project Zero
Project Zero
Security Archives - TechRepublic
Security Archives - TechRepublic
C
Cyber Attacks, Cyber Crime and Cyber Security
Security Latest
Security Latest
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
V
Vulnerabilities – Threatpost
C
CERT Recently Published Vulnerability Notes
S
Schneier on Security
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
I
Intezer
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
F
Full Disclosure
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
WordPress大学
WordPress大学
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
大猫的无限游戏
大猫的无限游戏
MyScale Blog
MyScale Blog
Hacker News: Ask HN
Hacker News: Ask HN
G
Google Developers Blog
H
Heimdal Security Blog
O
OpenAI News
Hugging Face - Blog
Hugging Face - Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LangChain Blog
C
Cisco Blogs
云风的 BLOG
云风的 BLOG
IT之家
IT之家
Cyberwarzone
Cyberwarzone
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Know Your Adversary
Know Your Adversary
博客园 - 聂微东
The Cloudflare Blog
C
Check Point Blog
K
Kaspersky official blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
月光博客
月光博客
T
Tor Project blog
T
Threat Research - Cisco Blogs
T
Tailwind CSS Blog
P
Proofpoint News Feed
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
A
About on SuperTechFans
小众软件
小众软件
Cloudbric
Cloudbric
A
Arctic Wolf

blag

SQLite prefixes its temp files with `etilqs_` - blag Setsum - order agnostic, additive, subtractive checksum - blag Oldest recorded transaction - blag Replacing a cache service with a database - blag SQLite commits are not durable under default settings - blag PSA: SQLite WAL checksums fail silently and may lose data - blag Rickrolling Turso DB (SQLite rewrite in Rust) - blag Collection of insane and fun facts about SQLite - blag How bloom filters made SQLite 10x faster - blag In search of a faster SQLite - blag Galloping Search - blag Building a distributed log using S3 (under 150 lines of Go) - blag Zero Disk Architecture - blag PSA: Most databases do not do checksums by default - blag PSA: SQLite does not do checksums - blag Disaggregated Storage - a brief introduction - blag Why does SQLite (in production) have such a bad rep? - blag SQLite Slaps - blag Now - blag Learning C - blag Snapshot Testing - blag Win: contribution to libSQL (SQLite) codebase - blag Errata in Hekaton MVCC paper - blag Internet is wholesome: MVCC edition - blag It is becoming difficult for me to be productive in Python - blag MongoDB secondary only index - blag Introducing CaskDB – a project to teach you writing a key-value store - blag Recurse Center: Winter Break - blag Recurse Center Day 24: Hacking Go compiler to add a new keyword - blag Recurse Center Day 20: Django v4 upgrade (from v1) - blag Recurse Center Day 19 - blag Recurse Center Day 18 - blag Recurse Center Day 17 - blag Recurse Center Day 16: Open Source - blag Recurse Center Day 15: B Tree Algorithms - blag Recurse Center Day 14: NoSQL Transactions - blag Recurse Center Day 13: Why 'Raft'? - blag Recurse Center Day 12: Isolation Anomalies - blag Recurse Center Day 11: B Tree Insertions - blag Recurse Center Day 10: Learning Distributed Systems - blag Recurse Center Day 9: Papers We Love - blag Recurse Center Day 8: B Tree Fill Factor (Part 2) - blag Recurse Center Day 7: Basics of ncurses - blag Recurse Center Day 6: B Tree Root - blag Recurse Center First Week - blag Recurse Center Day 5: Garbage Collection Algorithms - blag Recurse Center Day 4: B Tree fill factor - blag Recurse Center Day 3: Hammock Driven Development - blag Recurse Center Day 2: BTree Node - blag Recurse Center Day 1: init - blag What I want to do at Recurse Center - blag Accepted to the Recurse Center! - blag Towards Inserting One Billion Rows in SQLite Under A Minute - blag Marshaling Struct with Special Fields to JSON in Golang - blag I ended up adding duplicate records on a unique index in MongoDB - blag Setting up Github Actions for Hugo - blag Moving to Hugo - blag Catching SIGTERM in Python - blag Git/Github fork-pull request-update cycle - blag Using uWSGI with Python 3 - blag Staying Ahead of Amazon, in Amazon Treasure Hunt Contest - blag How I Am Maintaining Multiple Emails For Git On A Same Machine - blag An exploit on Gaana.com gave me access to their entire User Database - blag Flashing Asus-WRT Merlin by XVortex on NetGear NightHawk R7000 - blag Install Windows 8 UEFI on Legacy BIOS with Clover (and Dual boot with Yosemite) - blag Scraping Javascript page using Python - blag Installing Transmission (remote and CLI) client on Raspberry Pi - blag About - blag Projects - blag
When is my Cake Day? - blag
2015-11-21 · via blag

kek

Reddit gives all the user info in a handy JSON at this URL: https://www.reddit.com/user/<username here>/about.json

example: https://www.reddit.com/user/spez/about.json

The created_utc field in data is the date of user’s registration aka Cake Day in unix epoch format (in UTC) and we can easily convert that to readable format:

>>> import time
>>> time.strftime("%D", time.gmtime(1118030400))
'06/06/05'

Using Python Requests, we can turn this into a handy function:

import time
import requests

def get_my_cake_day(username):
    url = "https://www.reddit.com/user/{}/about.json".format(username)
    r = requests.get(url)
    created_at = r.json()['data']['created_utc']
    return time.strftime("%D", time.gmtime(created_at))

Though above function will work, but soon it will start throwing HTTP 429 error i.e Too Many Requests. Thing is, Reddit doesn’t really like when someone tries to fetch the data like this. The requests are made directly on Reddit servers without using the API. Now if you have want to find cake day of hundreds of users, you cannot use this method.

Solution? Use Reddit’s API. In Python, we will use praw and prawoauth2. praw is a Python wrapper for Reddit’s API and prawoauth2 helps dealing with OAuth2.

Let’s start by installing praw:

pip install praw

Now we can convert the get_my_cake_day to praw version and get the user details like this:

import time
import praw

reddit_client = praw.Reddit(user_agent='my amazing cake day bot')

def get_my_cake_day(username):
    redditor = reddit_client.get_redditor(username)
    return time.strftime("%D", time.gmtime(redditor.created_utc))

Above code pretty much self explanatory. What if the user doesn’t exist or shadowbanned? In such cases, praw throws an exception: praw.errors.NotFound. Lets modify get_my_cake_day to catch this:

def get_my_cake_day(username):
    try:
        redditor = reddit_client.get_redditor(username)
        return time.strftime("%D", time.gmtime(redditor.created_utc))
    except praw.errors.NotFound:
        return 'User does not exist or shadowbanned'

This is better compared to earlier version and we will stop getting rate limit errors often. Also, praw will handle such cases and makes requests again to fetch the data. But what if we want to increase the limit?

The above requests are not authenticated, meaning Reddit does not recognise your app. However, if we register this app in Reddit and let Reddit know, then requests limits will increase. So to authenticate our app over Oauth2, we will use prawoauth2. Lets install it first:

pip install prawoauth2

Follow the simple steps here to register your app on Reddit. Once done, you will get app_token and app_secret. Then you need to get access_token and refresh_token. You could use this handy onetime.py script. For detailed instructions check the documentation of prawoauth2. You should never make app_token, app_secret, access_token and refresh_token public and never commit them to version control. Keep them always secret.

Here is the complete script using prawoauth2:

import time
import praw

from secret import (app_key, app_secret, access_token, refresh_token,
                    user_agent, scopes)

reddit_client = praw.Reddit(user_agent='my amazing cakeday bot')
oauth_helper = PrawOAuth2Mini(reddit_client, app_key=app_key,
                              app_secret=app_secret,
                              access_token=access_token,
                              refresh_token=refresh_token, scopes=scopes)


def get_my_cake_day(username):
    try:
        redditor = reddit_client.get_redditor(username)
        return time.strftime("%D", time.gmtime(redditor.created_utc))
    except praw.errors.NotFound:
        return 'User does not exists or shadowbanned'

Again, pretty much self explanatory. If your tokens are correct and once PrawOAuth2Mini is initialized properly, there will be no issues with the app and you will have twice as many requests as compared to unauthenticated version.

Want to see above app in action? Check this - kekday. The app is open source and released under MIT License.