old snappy master
parent
e9f3404d1c
commit
345673a480
@ -1,79 +0,0 @@
|
||||
import os, requests, config
|
||||
from snapchat import get_stories, get_highlight_stories, get_all_users_data
|
||||
|
||||
def get_file_extension(url):
|
||||
response = requests.head(url)
|
||||
if response.status_code != 200:
|
||||
print(f"Failed to access media {url}")
|
||||
return None
|
||||
|
||||
content_type = response.headers.get('Content-Type', '')
|
||||
if 'image' in content_type:
|
||||
return '.jpg'
|
||||
elif 'video' in content_type:
|
||||
return '.mp4'
|
||||
else:
|
||||
print(f"Unknown content type for media {url}")
|
||||
return None
|
||||
|
||||
import re
|
||||
def extract_file_type(url):
|
||||
# Use a regular expression to extract the file type number
|
||||
match = re.search(r"/d/[^.]+\.([0-9]+)\.", url)
|
||||
if match:
|
||||
return match.group(1) # Return the number as a string
|
||||
return None
|
||||
|
||||
def map_file_type_to_extension(urls):
|
||||
file_type_to_extension = {}
|
||||
seen_file_types = set()
|
||||
|
||||
for url in urls:
|
||||
# Extract the file type number
|
||||
file_type_number = extract_file_type(url)
|
||||
if not file_type_number:
|
||||
continue
|
||||
|
||||
# Skip if we've already checked this file type
|
||||
if file_type_number in seen_file_types:
|
||||
continue
|
||||
|
||||
# Use the get_file_extension function to determine the extension
|
||||
file_extension = get_file_extension(url)
|
||||
if file_extension:
|
||||
file_type_to_extension[file_type_number] = file_extension
|
||||
seen_file_types.add(file_type_number)
|
||||
|
||||
return file_type_to_extension
|
||||
|
||||
def main():
|
||||
cursor.execute("SELECT username FROM following WHERE platform = 'snapchat' ORDER BY id DESC")
|
||||
usernames = [row[0] for row in cursor.fetchall()]
|
||||
|
||||
snapchat_users_data = get_all_users_data(usernames)
|
||||
|
||||
all_stories = [get_stories(data) + get_highlight_stories(data) for data in snapchat_users_data.values()]
|
||||
|
||||
processed_stories = []
|
||||
for stories in all_stories:
|
||||
processed_stories.extend(stories)
|
||||
|
||||
all_urls = [story['url'] for story in processed_stories]
|
||||
|
||||
# Map file type numbers to extensions
|
||||
file_type_to_extension = map_file_type_to_extension(all_urls)
|
||||
|
||||
# Print the mapping
|
||||
print("File Type to Extension Mapping:")
|
||||
for file_type, extension in file_type_to_extension.items():
|
||||
print(f"File Type {file_type}: {extension}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('Starting snappy...')
|
||||
|
||||
db, cursor = config.gen_connection()
|
||||
obj_storage = config.get_storage()
|
||||
|
||||
main()
|
||||
|
||||
print("Processing completed.")
|
||||
Loading…
Reference in New Issue