tweepy init
This commit is contained in:
parent
18abdbd0d8
commit
29dfbd41ad
19
tweepy/.direnv/bin/nix-direnv-reload
Executable file
19
tweepy/.direnv/bin/nix-direnv-reload
Executable file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
if [[ ! -d "/home/jawz/Development/Scripts/tweepy" ]]; then
|
||||
echo "Cannot find source directory; Did you move it?"
|
||||
echo "(Looking for "/home/jawz/Development/Scripts/tweepy")"
|
||||
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# rebuild the cache forcefully
|
||||
_nix_direnv_force_reload=1 direnv exec "/home/jawz/Development/Scripts/tweepy" true
|
||||
|
||||
# Update the mtime for .envrc.
|
||||
# This will cause direnv to reload again - but without re-building.
|
||||
touch "/home/jawz/Development/Scripts/tweepy/.envrc"
|
||||
|
||||
# Also update the timestamp of whatever profile_rc we have.
|
||||
# This makes sure that we know we are up to date.
|
||||
touch -r "/home/jawz/Development/Scripts/tweepy/.envrc" "/home/jawz/Development/Scripts/tweepy/.direnv"/*.rc
|
||||
1880
tweepy/.direnv/nix-profile-24.05-qszplw617r895nbc.rc
Normal file
1880
tweepy/.direnv/nix-profile-24.05-qszplw617r895nbc.rc
Normal file
File diff suppressed because it is too large
Load Diff
1
tweepy/.envrc
Normal file
1
tweepy/.envrc
Normal file
@ -0,0 +1 @@
|
||||
use nix
|
||||
71
tweepy/find_tweet_user.py
Normal file
71
tweepy/find_tweet_user.py
Normal file
@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
import time
|
||||
import shutil
|
||||
from pathlib import Path
|
||||
from selenium import webdriver
|
||||
from selenium.webdriver.firefox.service import Service
|
||||
from webdriver_manager.firefox import GeckoDriverManager
|
||||
|
||||
# Path to your Firefox profile
|
||||
firefox_profile_path = "/home/jawz/.mozilla/firefox/yw8fhvh4.default-release"
|
||||
|
||||
# Initialize the Firefox driver with the existing profile
|
||||
options = webdriver.FirefoxOptions()
|
||||
options.add_argument("-profile")
|
||||
options.add_argument(firefox_profile_path)
|
||||
|
||||
service = Service(GeckoDriverManager().install())
|
||||
driver = webdriver.Firefox(service=service, options=options)
|
||||
|
||||
# Directory containing the image files
|
||||
source_dir = Path("/mnt/server/jawz/Pictures/To Organize")
|
||||
target_dir = Path("/mnt/server/pool/scrapping/JawZ/gallery-dl")
|
||||
delete_dir = Path("/mnt/server/jawz/Pictures/To Organize/to_delete/")
|
||||
|
||||
|
||||
# Function to get Twitter username from tweet status ID
|
||||
def get_username_from_tweet_id(tweet_id):
|
||||
url = f"https://x.com/anyuser/status/{tweet_id}"
|
||||
driver.get(url)
|
||||
time.sleep(2.5) # Wait for the page to load
|
||||
fixed_url = driver.current_url
|
||||
username = fixed_url.replace("https://x.com/", "").replace(
|
||||
f"/status/{tweet_id}", ""
|
||||
)
|
||||
|
||||
return username
|
||||
|
||||
|
||||
# Extract tweet IDs, ensure they are unique and sorted
|
||||
file_ids = map(lambda x: x.name.split("_")[0], source_dir.iterdir())
|
||||
tweet_ids = sorted(set(file_ids))[:49]
|
||||
|
||||
# Iterate through unique and sorted tweet IDs
|
||||
for tweet_id in tweet_ids:
|
||||
username = get_username_from_tweet_id(tweet_id)
|
||||
if username is None:
|
||||
continue
|
||||
if username == "anyuser":
|
||||
continue
|
||||
dest_dir = Path(target_dir, username)
|
||||
if not dest_dir.exists():
|
||||
continue
|
||||
if not dest_dir.is_dir():
|
||||
continue
|
||||
|
||||
files_to_move = filter(lambda x: tweet_id in x.name, source_dir.iterdir())
|
||||
for file in files_to_move:
|
||||
target_file = Path(dest_dir, file.name)
|
||||
if target_file.exists():
|
||||
delete_file = Path(delete_dir, file.name)
|
||||
shutil.move(str(file.resolve()), str(delete_file.resolve()))
|
||||
print(f"Moved {file.name} to {str(delete_file.resolve())}")
|
||||
continue
|
||||
# If file does not exist in target_dir, move it from source_dir to target_dir
|
||||
shutil.move(str(file.resolve()), str(target_file.resolve()))
|
||||
print(f"Moved {file.name} to {str(target_file.resolve())}")
|
||||
|
||||
|
||||
# Close the driver
|
||||
driver.quit()
|
||||
18
tweepy/shell.nix
Normal file
18
tweepy/shell.nix
Normal file
@ -0,0 +1,18 @@
|
||||
{ pkgs ? import <nixpkgs> { } }:
|
||||
|
||||
with pkgs;
|
||||
|
||||
mkShell {
|
||||
packages = [
|
||||
geckodriver
|
||||
(python3.withPackages (ps:
|
||||
with ps; [
|
||||
tweepy
|
||||
requests
|
||||
beautifulsoup4
|
||||
selenium
|
||||
webdriver-manager
|
||||
]))
|
||||
];
|
||||
buildInputs = [ ];
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user