Skip to content

Commit

Permalink
Replace "\n" with n in Python scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin-Loison committed Jul 28, 2023
1 parent 41c56b3 commit de70cf7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions tools/minimizeCURL.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def isCommandStillFine(command):
print(len(command))
# To verify that the user provided the correct `wantedOutput` to keep during the minimization.
if not isCommandStillFine(command):
print("The wanted output isn't contained in the result of the original curl command!")
print('The wanted output isn\'t contained in the result of the original curl command!')
exit(1)

if removeHeaders:
Expand Down Expand Up @@ -217,7 +217,7 @@ def getPaths(d):
break

command = command.replace(' --compressed', '')
command = command.replace(" --data-raw ''", '')
command = command.replace(' --data-raw \'\'', '')

HTTP_METHOD = ' -X POST'

Expand Down
16 changes: 8 additions & 8 deletions tools/simplifyCURL.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def exec(cmd):

#print(line)

"""
'''
two approaches:
1. block manually some useless pattern
2. automatically remove some patterns while keeping needle retrieved
"""
'''

# beautify: echo '{JSON}' | python -m json.tool

Expand All @@ -39,7 +39,7 @@ def exec(cmd):
toRemoves = [' -X POST']
# could also make one big but doing like currently we give some semantical structure and can then for instance make bruteforce
toReplaces = [['curl', 'curl -s'], ['2.20220119.05.00', '2.2022011'], ['1.20220125.01.00', '1.2022012'], ['%3D', '=']] # 2.20220201.05.00 -> 2.20220201
#dataRawNeedle = " --data-raw '"
#dataRawNeedle = ' --data-raw \''
contextToRemoves = ['adSignalsInfo', 'user', 'request', 'clickTracking', 'clientScreenNonce']
clientToRemoves = ['hl', 'gl', 'remoteHost', 'deviceMake', 'deviceModel', 'userAgent', 'osName', 'osVersion', 'originalUrl', 'platform', 'clientFormFactor', 'configInfo', 'browserName', 'browserVersion', 'visitorData', 'screenWidthPoints', 'screenHeightPoints', 'screenPixelDensity', 'screenDensityFloat', 'utcOffsetMinutes', 'userInterfaceTheme', 'mainAppWebInfo', 'timeZone', 'playerType', 'tvAppInfo', 'clientScreen']
generalToRemoves = ['webSearchboxStatsUrl', 'playbackContext', 'cpn', 'captionParams', 'playlistId']
Expand All @@ -51,21 +51,21 @@ def delete(variable, sub):
def treat(line):
for headerToRemove in headersToRemove:
#line = re.sub(r"-H '" + headerToRemove + ": [^']'", '', line)
line = re.sub(" -H\s+'" + headerToRemove + "(.+?)'", '', line) # can starts with r"XYZ"
line = re.sub(f' -H\s+\'{headerToRemove}(.+?)\'', '', line) # can starts with r"XYZ"
for toRemove in toRemoves:
line = line.replace(toRemove, '')
for toReplace in toReplaces:
needle, replaceWith = toReplace
line = line.replace(needle, replaceWith)
#if dataRawNeedle in line:
regex = "--data-raw\s+'(.+?)'"
regex = '--data-raw\s+\'(.+?)\''
search = re.search(regex, line)

if search:
dataRaw = search.group(1)
#print(dataRaw)
#lineParts = line.split(dataRawNeedle)
#linePartsParts = lineParts[1].split("'")
#linePartsParts = lineParts[1].split('\'')
#dataRaw = linePartsParts[0] # could also use a regex
dataRawJson = json.loads(dataRaw)
for contextToRemove in contextToRemoves:
Expand All @@ -77,8 +77,8 @@ def treat(line):
delete(dataRawJson, generalToRemove)
newDataRaw = json.dumps(dataRawJson, separators=(',', ':'))
#print(json.dumps(dataRawJson, separators=(',', ':'), indent = 4))
line = re.sub(regex, "--data-raw '" + newDataRaw + "'", line)
#line = lineParts[0] + dataRawNeedle + newDataRaw + "'"# + linePartsParts[1]
line = re.sub(regex, '--data-raw \'{newDataRaw}\'', line)
#line = lineParts[0] + dataRawNeedle + newDataRaw + '\''# + linePartsParts[1]
return line

cmd = treat(line)
Expand Down

0 comments on commit de70cf7

Please sign in to comment.