Skip to content

Instantly share code, notes, and snippets.

@Luro02
Last active Mar 30, 2018
Embed
What would you like to do?
if you never installed python or don't have panda + wget installed (python3 modules) then execute the install_dep.bat first
@echo off
WHERE python
IF %ERRORLEVEL% NEQ 0 (
IF NOT EXIST Anaconda3-5.0.1-Windows-x86_64.exe wget --no-check-certificate https://repo.continuum.io/archive/Anaconda3-5.0.1-Windows-x86_64.exe
start /wait Anaconda3-5.0.1-Windows-x86_64.exe
echo press a button if the installer closed !
pause
)
IF NOT EXIST psdle.py wget --no-check-certificate https://gist.githubusercontent.com/Gnarmagon/1cf55fd844779f69791e9bad600aaae6/raw/e7464647285cc08f9ce070bea6722f10fedffd67/psdle.py
pip install wget
pip install pandas
pause
exit
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-#
import os
import sys
import csv
from subprocess import Popen, PIPE
import pandas as pd
import wget
def exists(path):
"""Test whether a path exists. Returns False for broken symbolic links"""
try:
st = os.stat(path)
except os.error:
return False
return True
def filewrite(var):
"""writes to the output file"""
with open("export.txt", 'a', encoding='utf-8') as f:
f.write(var + '\n')
def search_cid(file, cid2):
"""
get the Line where the cid is located.
"""
with open(file, 'r', encoding="utf-8") as file2:
reader = csv.reader(file2)
for i, row in enumerate(reader):
for column in enumerate(row):
if cid2 in column:
return i, cid2
return None, cid2
def nonpdrm(link1, link2, link3, link4):
"""
create the 4 CSV Files needed for next step
"""
def syscmd(cmd):
"""
executes the given command with a better way than using
os.system() (I don't know why but it seems to be bad practice !)
It also returns the exe output instead of printing it :)
"""
cmoa = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE)
output, error = cmoa.communicate()
return output, error
def download(urllink, filename):
"""
download function....
"""
wget.download(urllink, filename)
def database(link1, link2, link3, link4):
"""
I know that isn't intended this way but it's easier lol
"""
download(link1, "data_0.tsv")
download(link2, "data_1.tsv")
download(link3, "data_2.tsv")
download(link4, "data_3.tsv")
# convert the tsv's to csv's
syscmd('cat data_0.tsv | tr "\\t" "," > data_0.csv')
syscmd('cat data_1.tsv | tr "\\t" "," > data_1.csv')
syscmd('cat data_2.tsv | tr "\\t" "," > data_2.csv')
syscmd('cat data_3.tsv | tr "\\t" "," > data_3.csv')
# remove old files
os.remove("data_0.tsv")
os.remove("data_1.tsv")
os.remove("data_2.tsv")
os.remove("data_3.tsv")
return None
database(link1, link2, link3, link4)
def database_cleanup():
"""
cleanup <3
"""
os.remove("data_0.csv")
os.remove("data_1.csv")
os.remove("data_2.csv")
os.remove("data_3.csv")
return None
# these files can cause problems if they still/already exist !
# I know it looks beautiful XD
if exists("export.txt") is True:
os.remove("export.txt")
if exists("data_0.csv") is True:
os.remove("data_0.csv")
if exists("data_0.tsv") is True:
os.remove("data_0.tsv")
if exists("data_1.csv") is True:
os.remove("data_1.csv")
if exists("data_1.tsv") is True:
os.remove("data_1.tsv")
if exists("data_2.csv") is True:
os.remove("data_2.csv")
if exists("data_2.tsv") is True:
os.remove("data_2.tsv")
if exists("data_3.csv") is True:
os.remove("data_3.csv")
if exists("data_3.tsv") is True:
os.remove("data_3.tsv")
# Stuff to do before:
if exists("psdle.csv") is False:
sys.exit("Please rename your psdle file to 'psdle.csv' and put it in the same directory !")
# gets user input
region = input("Please enter your Region (Region-Codes: USA, EU, JP, ASIA): ")
download_games = input("Enter Link from 'README 2.0' to the TSV File for Games: ")
download_dlc = input("Enter Link from 'README 2.0' to the TSV File for DLCs: ")
download_theme = input("Enter Link from 'README 2.0' to the TSV File for Themes: ")
vita_psm = input("Enter Link from 'README 2.0' to the TSV File for PSM: ")
# if you want to skip it replace the input(...) with the Url that you normally paste in cmd (looks like this):
# download_games = "http://www.google.com/"
df = pd.read_csv("psdle.csv", skipinitialspace=False, header=None, skiprows=1)
name = df[0].tolist()
link = df[1].tolist()
cid = df[2].tolist()
size = df[3].tolist()
# removes last entry from list (not needed) (it's the column name)
del name[-1]
del link[-1]
del cid[-1]
del size[-1]
nonpdrm(download_games, download_dlc, download_theme, vita_psm)
# checks all tabs/databases for the cid...
# is problematic if the cid exists and for example the link is missing O.O
for element in cid:
line, cid3 = search_cid("data_0.csv", element)
if line is None:
line, cid3 = search_cid("data_1.csv", cid3)
if line is None:
line, cid3 = search_cid("data_2.csv", cid3)
if line is None:
line, cid3 = search_cid("data_3.csv", cid3)
if line is None:
position = cid.index(cid3)
val = "PSV" + ', ' + region + ', ' + name[position] + ", " + link[position] + ", " + "MISSING" + ", " + cid3
filewrite(val)
database_cleanup()
print("\n\nFinished, you can now add to the PUBLIC File from the export.txt")
@TheRadziu
Copy link

TheRadziu commented Dec 2, 2017

nice! Added it to the readme 2.0. Can you add optional sha256 to it as well ?
And ps3 support, because as far as I can see it only generates output for vita

@catchra
Copy link

catchra commented Mar 13, 2018

X:\psdle>psdle.py
Please enter your Region (Region-Codes: USA, EU, JP, ASIA): JP
Enter Link from 'README 2.0' to the TSV File for Games: https://nopaystation.com/tsv/PSV_GAMES.tsv
Enter Link from 'README 2.0' to the TSV File for DLCs: https://nopaystation.com/tsv/PSV_DLCS.tsv
Enter Link from 'README 2.0' to the TSV File for Themes: https://nopaystation.com/tsv/PSV_THEMES.tsv
Enter Link from 'README 2.0' to the TSV File for PSM: https://nopaystation.com/tsv/PSM_GAMES.tsv
100% [............................................................................] 202992 / 202992Traceback (most recent call last):
  File "X:\psdle\psdle.py", line 140, in <module>
    line, cid3 = search_cid("data_0.csv", element)
  File "X:\psdle\psdle.py", line 27, in search_cid
    with open(file, 'r', encoding="utf-8") as file2:
FileNotFoundError: [Errno 2] No such file or directory: 'data_0.csv'

@dark-kota
Copy link

dark-kota commented Mar 14, 2018

@catchra if you are using Windows, replace "cat" with "type" on line 66-69, then it'll work fine.

@catchra
Copy link

catchra commented Mar 14, 2018

@dark-kota thx that fix it

@azumukupoe
Copy link

azumukupoe commented Mar 30, 2018

bat doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment