From ea7834d719a03659f9f12d5bc2dd8348ef847a6d Mon Sep 17 00:00:00 2001 From: adelorenzo Date: Sat, 30 Dec 2023 01:10:44 +0100 Subject: [PATCH] Sat Dec 30 01:10:44 AM CET 2023 --- gen_ports.py | 2 ++ numbers_db.sqlite | Bin 8192 -> 8192 bytes ports.py | 35 +++++++++++++++++++++++++++++++++++ random_numbers.db | Bin 0 -> 8192 bytes 4 files changed, 37 insertions(+) mode change 100644 => 100755 gen_ports.py create mode 100644 ports.py create mode 100644 random_numbers.db diff --git a/gen_ports.py b/gen_ports.py old mode 100644 new mode 100755 index 056453c..f579070 --- a/gen_ports.py +++ b/gen_ports.py @@ -1,3 +1,5 @@ +#!/usr/bin/python3 + import sqlite3 import random import uuid diff --git a/numbers_db.sqlite b/numbers_db.sqlite index 6b9f7f98c6a775e15cb76945dac1b22732a6ae61..551795832b96201cba6c41f9771f931e9d642d46 100644 GIT binary patch delta 277 zcmWm8JxT;Y5QgC%$K6azO*PzTpk%6lW~#CUlf^(x#K@q#dKy!6!Hta+uOMhD!V2EO zOz;?9!4|&o`QTkI*UN{)X8w3|0&{bGdAehaX<%bu^S-~gf~O6f?ap9f;2U1y7S3Vu zc5?uC-K@Q6{TOHr>@jN?(K8b=i^Zw1+Ekd!P|U}5xBYK>8z^Z+Cvifb-Gp4MMW&LK zdz(^H^YYuZ)rv?MDGo@1JbD#}(NV$_MkVjc&|hgbKTWq)aS7sLR6!wT^tB14^o%{( lq#-0FRrB@SHPz-~oy%^(p=7C+ZGB0#DaS!=9Y^zd{|8+EMEU># delta 187 zcmWm4F>V4e5J1t{EHsg#IRIRMl?Hk3F&KaS~2J z!xh+6U;29es$U%^)#x;R#}UlS{S5#ryaHbTKG*nt!Od%pJHQ*BareJY{p_o$>usI2 zGoqn(?TfOpcGp6New$cb^^c4Cqe`;b^rhX diff --git a/ports.py b/ports.py new file mode 100644 index 0000000..1326d3d --- /dev/null +++ b/ports.py @@ -0,0 +1,35 @@ +import sqlite3 +import random +from time import sleep + +# Create a SQLite database and table if not exists +conn = sqlite3.connect('random_numbers.db') +c = conn.cursor() + +try: + c.execute("""CREATE TABLE IF NOT EXISTS random_numbers(id INTEGER PRIMARY KEY, number INT)""") + conn.commit() +except: + pass + +def generate_and_update(): + random_number = random.randint(32768, 65535) + c.execute("SELECT COUNT(*) FROM random_numbers WHERE number=?", (random_number,)) + count = c.fetchone()[0] + + if count == 0: + c.execute("INSERT INTO random_numbers(number) VALUES(?)", (random_number,)) + conn.commit() + print(f"{random_number}") + else: + raise RuntimeError("No unique number found.") + +def main(): + try: + generate_and_update() + except RuntimeError as e: + print(e) + print("Try running the script again to get a new unique number.") + +if __name__ == "__main__": + main() diff --git a/random_numbers.db b/random_numbers.db new file mode 100644 index 0000000000000000000000000000000000000000..c9ac3548c6a36a4894d0d764041bae5abaa1002d GIT binary patch literal 8192 zcmeI#u}i~16vy$qroO6ad2Zr%;9@{r99@hOq*_H|KsrfEA{I;wG5!Jm6VgG!MR0Ty zN1dv;I6A76gQ8<`G7qWH$;s{a$nni_aKmT2&5c?!i_K0uO~TB~sxhUtnm0x%RmoQ& zU;WYfPqDwrEBn8uqGq<1 z3mbcJ8n&W#vfVmJ8gaTmxGOCBo*Q^3a2INx89bY6My9$JcuSsd*8S?L>(|YSSD!XN zH_4eJZ}T#rD(>+ozw#45@&n)UHDB=spXUb{2tWV=5P$##AOHafKmY;|fB*#kU4Y7# zvQ+1VZ0Y+PjY>}f8j-#|)3EfeM