M .gitignore => .gitignore +1 -0
@@ 1,1 1,2 @@
output
+fetch
A Dockerfile => Dockerfile +4 -0
@@ 0,0 1,4 @@
+FROM python:alpine
+COPY . .
+RUN mkdir output
+CMD ["python", "sasha-fetch.py", "-d", "15", "output/fetch"]
M sasha-fetch.py => sasha-fetch.py +51 -27
@@ 1,8 1,23 @@
#!/usr/bin/env python3
+message = '''
+Sashanoraa
+----------
+Pronouns: any
+Gender: Non-binary / Gender Queer
+Matrix: @zethra:matrix.org
+Email: ben@benaaron.dev
+Mastodon: @zethra@fosstodon.org
+Website: sashanoraa.gay
+Protonmail: sashanoraa@protonmail.com
+'''.splitlines()
+
import sys
import math
import random
+import signal
+import argparse
+from time import sleep
COLOR_ANSI = (
(0x00, 0x00, 0x00), (0xcd, 0x00, 0x00),
@@ 75,34 90,43 @@ class TextColor:
])
return output
-f = open('profile')
-message = '''
-Sashanoraa
-----------
-Pronouns: any
-Gender: Non-binary / Gender Queer
-Matrix: @zethra:matrix.org
-Email: ben@benaaron.dev
-Mastodon: @zethra@fosstodon.org
-Website: sashanoraa.gay
-Protonmail: sashanoraa@protonmail.com
-'''.splitlines()
-
-img = f.read().splitlines()
-
-titles = TextColor()
-data = TextColor()
-# Set the data color seed to something far away from the title seed so they look different
-data.os = ((titles.os - 10 + 7) % 15) + 10
+def generate(args):
+ with open('profile') as f:
+ img = f.read().splitlines()
-output = open(sys.argv[1], 'w')
+ titles = TextColor()
+ data = TextColor()
+ # Set the data color seed to something far away from the title seed so they look different
+ data.os = ((titles.os - 10 + 7) % 15) + 10
-for (i, m) in zip(img, message):
- if ':' in m:
- parts = m.split(':')
- output.write(f'{i} {titles.apply_color(parts[0])}: {data.apply_color(":".join(parts[1:]))}\n')
+ with open(args.output, 'w') as output:
+ for (i, m) in zip(img, message):
+ if ':' in m:
+ parts = m.split(':')
+ output.write(f'{i} {titles.apply_color(parts[0])}: {data.apply_color(":".join(parts[1:]))}\n')
+ else:
+ output.write(f'{i} {titles.apply_color(m)}\n')
+
+ for i in img[len(message):]:
+ output.write(i + '\n')
+
+def main():
+ parser = argparse.ArgumentParser(description="Generate cool neofetch like card")
+ parser.add_argument('output', help='Path to output to')
+ parser.add_argument('-d', type=float, help='Run in daemon mode, regenerating output every N minutes')
+ args = parser.parse_args()
+ if args.d:
+ wait_time = int(args.d * 60)
+ signal.signal(signal.SIGINT, lambda s, f: sys.exit(0))
+ signal.signal(signal.SIGTERM, lambda s, f: sys.exit(0))
+ print(f'Generating fetch output in daemon mode every {args.d} minutes')
+ while True:
+ generate(args)
+ sleep(wait_time)
+ print('Updating fetch output')
else:
- output.write(f'{i} {titles.apply_color(m)}\n')
+ print('Generating fetch output')
+ generate(args)
-for i in img[len(message):]:
- output.write(i + '\n')
+if __name__ == '__main__':
+ main()