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 pathlib
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# ========== Main Script ==========
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-b", "--bs",
|
parser.add_argument("-b", "--bs",
|
||||||
default=512,
|
default=512,
|
||||||
help="block size",
|
help="block size",
|
||||||
metavar="bs")
|
metavar="bs")
|
||||||
parser.add_argument("input_file", help="input file to write")
|
parser.add_argument("input_file", help="input file to write")
|
||||||
parser.add_argument("output_file", help="output block device")
|
parser.add_argument("output_file", help="output block device")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
block_size = args.bs
|
block_size = args.bs
|
||||||
input_file = args.input_file
|
input_file = args.input_file
|
||||||
block_device = args.output_file
|
block_device = args.output_file
|
||||||
|
|
||||||
if not pathlib.Path(block_device).is_block_device():
|
if not pathlib.Path(block_device).is_block_device():
|
||||||
print(f"Error: {block_device} is not a block device")
|
print(f"Error: {block_device} is not a block device")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
print(f"Input file: {input_file}")
|
print(f"Input file: {input_file}")
|
||||||
print(f"Block device: {block_device}")
|
print(f"Block device: {block_device}")
|
||||||
print(f"Block size: {block_size}")
|
print(f"Block size: {block_size}")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.run(["dd", f"if={input_file}",
|
subprocess.run(["dd", f"if={input_file}",
|
||||||
f"of={block_device}",
|
f"of={block_device}",
|
||||||
f"bs={block_size}",
|
f"bs={block_size}",
|
||||||
"status=progress"], check=True)
|
"status=progress"], check=True)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
subprocess.run(['sync'])
|
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 ==========
|
# ========== Error Codes ==========
|
||||||
E_NOURLS = 2
|
E_NOURLS = 2
|
||||||
|
|
||||||
# =========== Functions ==========
|
# ========== Main Script ==========
|
||||||
if __name__ == '__main__':
|
parser = argparse.ArgumentParser()
|
||||||
parser = argparse.ArgumentParser()
|
parser.add_argument('-b', '--batchfile',
|
||||||
parser.add_argument('-b', '--batchfile',
|
type=str,
|
||||||
type=str,
|
nargs=1,
|
||||||
nargs=1,
|
help='provide the links from a text file')
|
||||||
help='provide the links from a text file')
|
parser.add_argument('-f', '--format',
|
||||||
parser.add_argument('-f', '--format',
|
type=str,
|
||||||
type=str,
|
default='opus',
|
||||||
default='opus',
|
help='the format to use')
|
||||||
help='the format to use')
|
parser.add_argument('-n', '--filename',
|
||||||
parser.add_argument('-n', '--filename',
|
type=str,
|
||||||
type=str,
|
help='downloaded filename (without extension)')
|
||||||
help='downloaded filename (without extension)')
|
parser.add_argument('urls',
|
||||||
parser.add_argument('urls',
|
nargs='*',
|
||||||
nargs='*',
|
help='video URLs')
|
||||||
help='video URLs')
|
args = parser.parse_args()
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
dl_opts = [YOUTUBE_DL_BIN,
|
dl_opts = [YOUTUBE_DL_BIN,
|
||||||
'--no-part',
|
'--no-part',
|
||||||
'--no-continue',
|
'--no-continue',
|
||||||
'--extract-audio',
|
'--extract-audio',
|
||||||
'--audio-format={args.format}']
|
'--audio-format={args.format}']
|
||||||
|
|
||||||
# filename handling
|
# filename handling
|
||||||
# if -b is used, DEFAULT_FILENAME must take precedence
|
# if -b is used, DEFAULT_FILENAME must take precedence
|
||||||
if args.filename:
|
if args.filename:
|
||||||
dl_opts.append('--output={args.filename}')
|
dl_opts.append('--output={args.filename}')
|
||||||
else:
|
else:
|
||||||
dl_opts.append('--output={DEFAULT_FILENAME}')
|
dl_opts.append('--output={DEFAULT_FILENAME}')
|
||||||
|
|
||||||
# URL handling
|
# URL handling
|
||||||
if args.batchfile:
|
if args.batchfile:
|
||||||
dl_opts.append(f"--batch-file={args.batchfile}")
|
dl_opts.append(f"--batch-file={args.batchfile}")
|
||||||
elif not args.urls:
|
elif not args.urls:
|
||||||
print("URLs are required")
|
print("URLs are required")
|
||||||
exit(E_NOURLS)
|
exit(E_NOURLS)
|
||||||
else:
|
else:
|
||||||
dl_opts.extend(args.urls)
|
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
|
return (mkel_temp/1000) - 273.15
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# ========== Main Script ==========
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('device', help='device node to retrieve\
|
parser.add_argument('device', help='device node to retrieve\
|
||||||
the temperature for', metavar='dev')
|
the temperature for', metavar='dev')
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
dev = args.device
|
dev = args.device
|
||||||
|
|
||||||
if verify_device_node(dev):
|
if verify_device_node(dev):
|
||||||
mkel = retrieve_smart_temp(dev)
|
mkel = retrieve_smart_temp(dev)
|
||||||
print(f"{dev}: {convert_to_celsius(mkel)}°C")
|
print(f"{dev}: {convert_to_celsius(mkel)}°C")
|
||||||
else:
|
else:
|
||||||
print("Not a device node.")
|
print("Not a device node.")
|
||||||
exit(1)
|
exit(1)
|
||||||
|
@ -4,13 +4,14 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
# ========== Constants ==========
|
||||||
WTTR_URI = 'http://wttr.in'
|
WTTR_URI = 'http://wttr.in'
|
||||||
|
|
||||||
if __name__ == '__main__':
|
# ========== Main Script ==========
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('location')
|
parser.add_argument('location')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
location = args.location
|
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