Browse Source

added two new arguments --all for entire pad content, --pad for specific pad

main
crunk 4 years ago
parent
commit
0740ba4789
  1. 34
      palanggana.py
  2. 28
      pyproject.toml

34
palanggana.py

@ -13,6 +13,7 @@ parser.add_argument(
required=True, required=True,
help="Add your magic word here", help="Add your magic word here",
) )
parser.add_argument( parser.add_argument(
"-k", "-k",
"--keep", "--keep",
@ -20,11 +21,27 @@ parser.add_argument(
action="store_true", action="store_true",
) )
parser.add_argument(
"-p",
"--pad",
help="specify a pad name, get only that pad",
)
parser.add_argument(
"-a",
"--all",
help="get all content from pad not just the lines containing the magic",
action="store_true",
)
# just a few variables that we will need # just a few variables that we will need
thepump = "https://etherpump.vvvvvvaria.org/" thepump = "https://etherpump.vvvvvvaria.org/"
args = parser.parse_args() args = parser.parse_args()
magicword = "__{0}__".format(f"{args.magic}".upper()) magicword = "__{0}__".format(f"{args.magic}".upper())
padname = f"{args.pad}"
keep = args.keep keep = args.keep
wholepad = args.all
def extractlinks(thewell): def extractlinks(thewell):
@ -43,6 +60,18 @@ def extracttext(thegoods):
"""extract the texts from the plain text links""" """extract the texts from the plain text links"""
plaintexts = [] plaintexts = []
for link in thegoods: for link in thegoods:
if padname and padname != "None":
strippedlink = (
link.replace(thepump, "")
.replace(".raw.txt", "")
.replace("p/", "")
)
if padname.lower() == strippedlink.lower():
res = req.get(link)
# print("pad found {0} with link {1}".format(padname, link))
plaintexts.append(res.text.splitlines())
return plaintexts
else:
res = req.get(link) res = req.get(link)
plaintexts.append(res.text.splitlines()) plaintexts.append(res.text.splitlines())
return plaintexts return plaintexts
@ -53,10 +82,15 @@ def extractmagic(plaintexts):
magiclines = [] magiclines = []
# print(magicword) # print(magicword)
for line in plaintexts: for line in plaintexts:
if not wholepad:
if magicword in line: if magicword in line:
if not keep: if not keep:
line = line.replace(magicword, "") line = line.replace(magicword, "")
magiclines.append(line) magiclines.append(line)
else:
if not keep:
line = line.replace(magicword, "")
magiclines.append(line)
return magiclines return magiclines

28
pyproject.toml

@ -0,0 +1,28 @@
# NOTE: you have to use single-quoted strings in TOML for regular expressions.
# It's the equivalent of r-strings in Python. Multiline strings are treated as
# verbose regular expressions by Black. Use [ ] to denote a significant space
# character.
[tool.black]
line-length = 79
target-version = ['py37', 'py38', 'py39']
include = '\.pyi?$'
exclude = '''
/(
\.eggs
| \.git
| \.hg
| \.mypy_cache
| \.tox
| \.venv
| _build
| buck-out
| build
| dist
# The following are specific to Black, you probably don't want those.
| blib2to3
| tests/data
| profiling
)/
'''
Loading…
Cancel
Save