Skip to content

Added tsv.py #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tsv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import os
import socket
import urllib.parse

def get_nas_ip():
nas_ip = input("Enter the IP address of your NAS: ").strip()
try:
socket.inet_aton(nas_ip) # Validate IP format
return nas_ip
except socket.error:
print("Invalid IP address format. Please try again.")
return get_nas_ip()

def get_protocol():
choice = input("Enter 1 for FTP or 2 for HTTP: ").strip()
if choice == "1":
return "ftp", 21 # Default FTP port
elif choice == "2":
return "http", 8000 # Default HTTP server port
else:
print("Invalid choice. Please enter 1 or 2.")
return get_protocol()

def generate_tsv(nas_ip, protocol, port):
tsv_file = "local_packages.tsv"

with open(tsv_file, "w", encoding="utf-8") as f:
# Write header
f.write("Title ID\tRegion\tName\tPKG direct link\tRAP\tContent ID\tLast Modification Date\tDownload .RAP file\tFile Size\tSHA256\n")

for file in os.listdir():
if file.endswith(".pkg"):
file_size = os.path.getsize(file)
encoded_file = urllib.parse.quote(file) # URL encode file name
pkg_link = f"{protocol}://{nas_ip}:{port}/{encoded_file}"
f.write(f"\t\t{file}\t{pkg_link}\t\t\t\t\t{file_size}\t\n")

print(f"TSV file '{tsv_file}' generated successfully.")

if __name__ == "__main__":
nas_ip = get_nas_ip()
protocol, port = get_protocol()
generate_tsv(nas_ip, protocol, port)