Remove 'if __name__ == __main__' clauses in all python scripts
This commit is contained in:
parent
24c4ae781b
commit
04aade74eb
54
ddusb.py
54
ddusb.py
@ -5,34 +5,34 @@ import argparse
|
||||
import pathlib
|
||||
import subprocess
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-b", "--bs",
|
||||
default=512,
|
||||
help="block size",
|
||||
metavar="bs")
|
||||
parser.add_argument("input_file", help="input file to write")
|
||||
parser.add_argument("output_file", help="output block device")
|
||||
args = parser.parse_args()
|
||||
# ========== Main Script ==========
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-b", "--bs",
|
||||
default=512,
|
||||
help="block size",
|
||||
metavar="bs")
|
||||
parser.add_argument("input_file", help="input file to write")
|
||||
parser.add_argument("output_file", help="output block device")
|
||||
args = parser.parse_args()
|
||||
|
||||
block_size = args.bs
|
||||
input_file = args.input_file
|
||||
block_device = args.output_file
|
||||
block_size = args.bs
|
||||
input_file = args.input_file
|
||||
block_device = args.output_file
|
||||
|
||||
if not pathlib.Path(block_device).is_block_device():
|
||||
print(f"Error: {block_device} is not a block device")
|
||||
exit(1)
|
||||
if not pathlib.Path(block_device).is_block_device():
|
||||
print(f"Error: {block_device} is not a block device")
|
||||
exit(1)
|
||||
|
||||
print(f"Input file: {input_file}")
|
||||
print(f"Block device: {block_device}")
|
||||
print(f"Block size: {block_size}")
|
||||
print(f"Input file: {input_file}")
|
||||
print(f"Block device: {block_device}")
|
||||
print(f"Block size: {block_size}")
|
||||
|
||||
try:
|
||||
subprocess.run(["dd", f"if={input_file}",
|
||||
f"of={block_device}",
|
||||
f"bs={block_size}",
|
||||
"status=progress"], check=True)
|
||||
except subprocess.CalledProcessError:
|
||||
exit(1)
|
||||
else:
|
||||
subprocess.run(['sync'])
|
||||
try:
|
||||
subprocess.run(["dd", f"if={input_file}",
|
||||
f"of={block_device}",
|
||||
f"bs={block_size}",
|
||||
"status=progress"], check=True)
|
||||
except subprocess.CalledProcessError:
|
||||
exit(1)
|
||||
else:
|
||||
subprocess.run(['sync'])
|
||||
|
75
dlaudio.py
75
dlaudio.py
@ -17,45 +17,44 @@ DEFAULT_FILENAME = f"{pathlib.Path.home()}/Music/%(title)s.%(ext)s"
|
||||
# ========== Error Codes ==========
|
||||
E_NOURLS = 2
|
||||
|
||||
# =========== Functions ==========
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-b', '--batchfile',
|
||||
type=str,
|
||||
nargs=1,
|
||||
help='provide the links from a text file')
|
||||
parser.add_argument('-f', '--format',
|
||||
type=str,
|
||||
default='opus',
|
||||
help='the format to use')
|
||||
parser.add_argument('-n', '--filename',
|
||||
type=str,
|
||||
help='downloaded filename (without extension)')
|
||||
parser.add_argument('urls',
|
||||
nargs='*',
|
||||
help='video URLs')
|
||||
args = parser.parse_args()
|
||||
# ========== Main Script ==========
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('-b', '--batchfile',
|
||||
type=str,
|
||||
nargs=1,
|
||||
help='provide the links from a text file')
|
||||
parser.add_argument('-f', '--format',
|
||||
type=str,
|
||||
default='opus',
|
||||
help='the format to use')
|
||||
parser.add_argument('-n', '--filename',
|
||||
type=str,
|
||||
help='downloaded filename (without extension)')
|
||||
parser.add_argument('urls',
|
||||
nargs='*',
|
||||
help='video URLs')
|
||||
args = parser.parse_args()
|
||||
|
||||
dl_opts = [YOUTUBE_DL_BIN,
|
||||
'--no-part',
|
||||
'--no-continue',
|
||||
'--extract-audio',
|
||||
'--audio-format={args.format}']
|
||||
dl_opts = [YOUTUBE_DL_BIN,
|
||||
'--no-part',
|
||||
'--no-continue',
|
||||
'--extract-audio',
|
||||
'--audio-format={args.format}']
|
||||
|
||||
# filename handling
|
||||
# if -b is used, DEFAULT_FILENAME must take precedence
|
||||
if args.filename:
|
||||
dl_opts.append('--output={args.filename}')
|
||||
else:
|
||||
dl_opts.append('--output={DEFAULT_FILENAME}')
|
||||
# filename handling
|
||||
# if -b is used, DEFAULT_FILENAME must take precedence
|
||||
if args.filename:
|
||||
dl_opts.append('--output={args.filename}')
|
||||
else:
|
||||
dl_opts.append('--output={DEFAULT_FILENAME}')
|
||||
|
||||
# URL handling
|
||||
if args.batchfile:
|
||||
dl_opts.append(f"--batch-file={args.batchfile}")
|
||||
elif not args.urls:
|
||||
print("URLs are required")
|
||||
exit(E_NOURLS)
|
||||
else:
|
||||
dl_opts.extend(args.urls)
|
||||
# URL handling
|
||||
if args.batchfile:
|
||||
dl_opts.append(f"--batch-file={args.batchfile}")
|
||||
elif not args.urls:
|
||||
print("URLs are required")
|
||||
exit(E_NOURLS)
|
||||
else:
|
||||
dl_opts.extend(args.urls)
|
||||
|
||||
subprocess.run(dl_opts)
|
||||
subprocess.run(dl_opts)
|
||||
|
24
drivetemp.py
24
drivetemp.py
@ -51,17 +51,17 @@ def convert_to_celsius(mkel_temp):
|
||||
return (mkel_temp/1000) - 273.15
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('device', help='device node to retrieve\
|
||||
the temperature for', metavar='dev')
|
||||
args = parser.parse_args()
|
||||
# ========== Main Script ==========
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('device', help='device node to retrieve\
|
||||
the temperature for', metavar='dev')
|
||||
args = parser.parse_args()
|
||||
|
||||
dev = args.device
|
||||
dev = args.device
|
||||
|
||||
if verify_device_node(dev):
|
||||
mkel = retrieve_smart_temp(dev)
|
||||
print(f"{dev}: {convert_to_celsius(mkel)}°C")
|
||||
else:
|
||||
print("Not a device node.")
|
||||
exit(1)
|
||||
if verify_device_node(dev):
|
||||
mkel = retrieve_smart_temp(dev)
|
||||
print(f"{dev}: {convert_to_celsius(mkel)}°C")
|
||||
else:
|
||||
print("Not a device node.")
|
||||
exit(1)
|
||||
|
@ -4,13 +4,14 @@
|
||||
import argparse
|
||||
import requests
|
||||
|
||||
# ========== Constants ==========
|
||||
WTTR_URI = 'http://wttr.in'
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('location')
|
||||
# ========== Main Script ==========
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('location')
|
||||
|
||||
args = parser.parse_args()
|
||||
location = args.location
|
||||
args = parser.parse_args()
|
||||
location = args.location
|
||||
|
||||
print(requests.get(f"{WTTR_URI}/{location}").text)
|
||||
print(requests.get(f"{WTTR_URI}/{location}").text)
|
||||
|
Loading…
x
Reference in New Issue
Block a user