From 1d0e0e54f663920a0992f1af5bd7d0b37eee537a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Tue, 4 Jun 2024 15:40:40 +0200 Subject: e --- skripti/earhorn_m3u.sh | 7 +- "skripti/r\305\241_glasbena_oprema.py" | 31 ++++++ skripti/stream_archive.sh | 37 +++++++ skripti/zone/axfr.py | 86 ---------------- skripti/zone/update.py | 174 --------------------------------- skripti/zone_axfr.py | 86 ++++++++++++++++ skripti/zone_update.py | 174 +++++++++++++++++++++++++++++++++ "skripti/\305\276" | 36 +++++++ "\305\241ola/ds2/teor.lyx" | 24 +++-- "\305\241ola/p2/dn/DN09b_63230317.c" | 48 +++++++++ 10 files changed, 427 insertions(+), 276 deletions(-) create mode 100644 "skripti/r\305\241_glasbena_oprema.py" create mode 100755 skripti/stream_archive.sh delete mode 100755 skripti/zone/axfr.py delete mode 100755 skripti/zone/update.py create mode 100755 skripti/zone_axfr.py create mode 100755 skripti/zone_update.py create mode 100644 "skripti/\305\276" create mode 100644 "\305\241ola/p2/dn/DN09b_63230317.c" diff --git a/skripti/earhorn_m3u.sh b/skripti/earhorn_m3u.sh index e89a151..4dae851 100755 --- a/skripti/earhorn_m3u.sh +++ b/skripti/earhorn_m3u.sh @@ -3,6 +3,7 @@ set -eo pipefail # $1 je prefix # $2 je prejšnji file (za caching dolžin) # $3=1 forsira cache kljub version failu +# zadnjega vnosa iz cache m3uja nikdar ne bom upošteval, ker je lahko nedokončan file (no, v earhornu ne, ampak v stream_archive.sh) echo "#EXTM3U" ver="#earhorn_m3u.sh različica 0" echo $ver @@ -23,9 +24,9 @@ do s=${time:4:2} dol="" if [ $cache -eq 1 ] - then - grep -B2 ^$1$file$ $2 && continue - fi + then # tu smatram, da vsaka datoteka zavzema 3 vrstice + head -n-3 $2 | grep -B2 ^$1$file$ && continue + fi # prvič v head ko rečem -n-3 in drugič v grep, ko rečem -B2 dol=`ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 $file | cut -d. -f1` echo "#EXTINF:$dol,Radijski arhiv" echo "#EXT-X-PROGRAM-DATE-TIME:${date}T$h:$m:${s}Z" diff --git "a/skripti/r\305\241_glasbena_oprema.py" "b/skripti/r\305\241_glasbena_oprema.py" new file mode 100644 index 0000000..8d53702 --- /dev/null +++ "b/skripti/r\305\241_glasbena_oprema.py" @@ -0,0 +1,31 @@ +#!/usr/bin/python3 +import feedparser +import yt_dlp +from ollama import Client +from bs4 import BeautifulSoup +client = Client(host='http://splet.4a.si:80') +model = "llama2:13b-chat-fp16" +prompt = "The document below is text extracted from a Slovene radio station containing a tracklist. Extract the tracklist form the text below and output a CSV table in format \"artist,track name,album,duration,label\". Example output:\n\nThe Prodigy,Firestarter,The Fat of the Land,4:42,XL\nBJÖRK,LION SONG,,6:16," +def opreme(): + r = [] + for entry in feedparser.parse("https://radiostudent.si/taxonomy/term/589/*/feed").entries: + oprema = {"id": int(entry.id.split(" ")[0]), "title": entry.title, "link": entry.link, "published": entry.published_parsed, "authors": []} + for author in entry.authors: + oprema["authors"].append(author.name) + summary = BeautifulSoup(entry.summary, features="html.parser") + body = None + for i in summary.findAll("div"): + if "class" in i.attrs: + if "field-name-body" in i.attrs["class"]: + body = i + break + if "" + if body == None: + raise Exception("body is None in " + entry.link) + body = body.text.replace("\r", "") + while "\n\n" in body: + body = body.replace("\n\n", "\n") + r.append(oprema) + return r +if __name__ == "__main__": + opreme() \ No newline at end of file diff --git a/skripti/stream_archive.sh b/skripti/stream_archive.sh new file mode 100755 index 0000000..b218246 --- /dev/null +++ b/skripti/stream_archive.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# $1 naj bo icecast host kruljo.radiostudent.si +# $2 naj bo icecast http port 8000 +# $3 naj bo icecast endpoint /ehiq +# $4 naj bo končnica datotek .mp3 +# v CWD delam imenike in datoteke in sem glede tega kompatibilen z earhornom: +# Posnetek 2024/06/03/202136.mp3 se začne 2024-06-03T20:21:36 vedno UTC. +# Posnetkov ne splittam na uro. Posnetek se splitta le takrat, ko se zgodi napaka (stream crkne) -- takrat začnem pisati v novo datoteko +# požvižgam se na vsebino datotek. zame so to le bajti. v tem nisem earhornski. +# earhornski nisem tudi zato, ker se zadnja datoteka stalno veča, kar se ne dogaja pri earhornu. na to bodite pozorni. k sreči earhorn_m3u.sh ve za to obnašanje +set -xeuo pipefail +host=$1 +port=$2 +endpoint=$3 +kon=$4 +mistakes=0 +while : +do + filename=`date --utc +%Y/%m/%d/%H%m%S$kon` + mkdir -p `cut -d/ -f1-3 <<<$filename` + start=$SECONDS + set +e + nc $host $port <<<"GET $endpoint HTTP/1.0"$'\r\n\r' > $filename + koda=$? + set -e + echo TCP PREKINJEN! ZAČENJAM NOV POSNETEK! IZHODNA KODA nc je $koda, datum je `date` + if [ $(($SECONDS-$start)) -lt 300 ] + then + mistakes=$(($mistakes+1)) + if [ $mistakes -gt 3 ] + then + sleep $((2**($mistakes-3))) + fi + else + mistakes=0 + fi +done diff --git a/skripti/zone/axfr.py b/skripti/zone/axfr.py deleted file mode 100755 index 11eaad9..0000000 --- a/skripti/zone/axfr.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/bin/python3 -import dns.zone -import dns.resolver -import json -import sys -domena = sys.argv[1] -strežniki = [dns.resolver.resolve(domena, "SOA")[0].mname] -for i in dns.resolver.resolve(domena, "NS"): - strežniki.append(i.target) -naslovi = [] -for strežnik in strežniki: - for i in dns.resolver.resolve(strežnik, "AAAA"): - naslovi.append(i.address) - for i in dns.resolver.resolve(strežnik, "A"): - naslovi.append(i.address) -for naslov in naslovi: # opcijsko dodaj tule kakšen try catch - zone = None - zone = dns.zone.from_xfr(dns.query.xfr(naslov, domena)) - if zone != None: - break -config = None -try: - config = json.loads(b''.join(zone["_urejevalnik"].get_rdataset(dns.rdataclass.IN, dns.rdatatype.TXT)[0].strings).decode()) -except KeyError: - pass -except json.decoder.JSONDecodeError: - pass -if config == None: - berime = """; Dobrodošli v preprost urejevalnik DNS zapisov. -; Komentarji se shranijo v DNS strežnik in so javni. Morajo biti na samostojnih vrsticah. -; Te komentarje z navodili lahko izbrišete -- ne bodo se ponovno pojavili. -; Nove zapise naložite na strežnik z ukazom zone/update.py zonefile.db -; Zapise prenesete iz strežnika z ukazom zone/axfr.py domena > zonefile.db -; Prva vrstica je konfiguracijski zapis v JSON obliki. Naslednje podatke lahko spremenite: -; "t": privzeti TTL, ki se uporabi, če zapis v datoteki nima TTLja -; "+": koliko naj prištejem serijski številki pred nalaganjem na strežnik - -""" - config = {"v": 0, "d": domena, "c": {"@ SOA": berime}, "t": 1, "+": 100, "i": {}} -configout = config.copy() -del configout["c"] -del configout["i"] -print(f"{json.dumps(configout)}") -for r in zone.iterate_rdatas(): - if r[0].to_unicode() == "_urejevalnik" or r[2].rdtype in [dns.rdatatype.RRSIG, dns.rdatatype.NSEC, dns.rdatatype.NSEC3, dns.rdatatype.DNSKEY]: - continue - commentkey = r[0].to_unicode() + " " + r[2].rdtype.name - if commentkey in config["c"].keys(): - print(config["c"][commentkey], end="") - del config["c"][commentkey] - konec = "\t" - if r[0].to_unicode() in config["i"].keys(): - konec = config["i"][r[0].to_unicode()] - print(r[0].to_unicode(), end=konec) - if r[1] != config["t"]: - print(r[1], end="") - print("\t", end="") - if r[2].rdclass != dns.rdataclass.IN: - print(r[2].rdataclass.name, end="\t") - print(r[2].rdtype.name, end="\t") - if r[2].rdtype == dns.rdatatype.TXT: - prvič = True - for string in r[2].strings: - if prvič: - prvič = False - else: - print(" ", end="") - bajti = b'' - for char in string: - if char < ord(b' '): - bajti += b'\\' + ("%03d" % ord(char)).encode() - else: - bajti += bytes([char]) - niz = "" - for znak in bajti.replace(b'\\', b'\\\\').replace(b'"', b'\\"').decode('utf-8', errors='surrogateescape'): - if '\udc80' <= znak <= '\udcff': - niz += '\\'+("%03d" % (ord(znak)-0xdc00)) - else: - niz += znak - - print('"' + niz + '"', end="") - else: - print(r[2].to_text(), end="") - print() -for i in config["c"].items(): - print(i[1], end="") diff --git a/skripti/zone/update.py b/skripti/zone/update.py deleted file mode 100755 index ead2c39..0000000 --- a/skripti/zone/update.py +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/python3 -import dns.zone -import dns.resolver -import dns.update -import dns.tsigkeyring -import json -import sys -import math -with open(sys.argv[1], "r") as db: - lines = db.readlines() -newconfig = json.loads(lines.pop(0)[:-1]) -domena = newconfig["d"] -strežniki = [dns.resolver.resolve(domena, "SOA")[0].mname] -naslovi = [] -for strežnik in strežniki: - for i in dns.resolver.resolve(strežnik, "AAAA"): - naslovi.append(i.address) - for i in dns.resolver.resolve(strežnik, "A"): - naslovi.append(i.address) -for naslov in naslovi: # opcijsko dodaj tule kakšen try catch - zone = None - zone = dns.zone.from_xfr(dns.query.xfr(naslov, domena)) - if zone != None: - break -config = None -try: - config = json.loads(b''.join(zone["_urejevalnik"].get_rdataset(dns.rdataclass.IN, dns.rdatatype.TXT)[0].strings).decode()) -except KeyError: - pass -except json.decoder.JSONDecodeError: - pass -if config == None: - config = {"v": 0, "d": domena, "c": {}, "t": 1, "+": 100, "i": {}} -rrs = [] -for r in zone.iterate_rdatas(): - if r[0].to_unicode() == "_urejevalnik" or r[2].rdtype in [dns.rdatatype.RRSIG, dns.rdatatype.NSEC, dns.rdatatype.NSEC3, dns.rdatatype.DNSKEY]: - continue - commentkey = r[0].to_unicode() + " " + r[2].rdtype.name - komentar = "" - if commentkey in config["c"].keys(): - komentar = config["c"][commentkey] - del config["c"][commentkey] - konec = "\t" - if r[0].to_unicode() in config["i"].keys(): - konec = config["i"][r[0].to_unicode()] - vrednost = "" - if r[2].rdtype == dns.rdatatype.TXT: - for string in r[2].strings: - bajti = b'' - for char in string: - if char < ord(b' '): - bajti += b'\\' + ("%03d" % ord(char)).encode() - else: - bajti += bytes([char]) - niz = "" - for znak in bajti.replace(b'\\', b'\\\\').replace(b'"', b'\\"').decode('utf-8', errors='surrogateescape'): - if '\udc80' <= znak <= '\udcff': - niz += '\\'+("%03d" % (ord(znak)-0xdc00)) - else: - niz += znak - vrednost = '"' + niz + '"' - else: - vrednost = r[2].to_text() - rrs.append((r[1], r[0].to_unicode(), komentar, None, r[2].rdclass, r[2].rdtype, vrednost)) -komentar = "" -lineno = 1 -novikomentarji = {} -novikonci = {} -keyring = None -plus = 0 -minus = 0 -if len(sys.argv) == 3: - with open(sys.argv[2]) as file: - ključ = file.read() - keyring = dns.tsigkeyring.from_text({ključ.split()[ključ.split().index("key")+1].replace('"', "").replace(";", ""): ključ.split()[ključ.split().index("secret")+1].replace('"', "").replace(";", "")}) -update = dns.update.Update(domena, keyring=keyring) -while True: - try: - lineno += 1 - line = lines.pop(0)[:-1] # odstranimo zadnji \n, ki ga zraven da .readlines - if len(line.split()) == 0 or line[0] == ';' or line[0] == '#' or line[0] == '/': - komentar += line + "\n" - continue - ime = line.split()[0] - konec = "" - index = len(ime) - while line[index] in ["\t", " "]: - konec += line[index] - index += 1 - nizi = line.split()[1:] - tip = None - razred = None - ttl = None - while tip == None: - try: - ttl = int(nizi[0]) - nizi.pop(0) - except ValueError: - pass - try: - razred = dns.rdataclass.from_text(nizi[0]) - nizi.pop(0) - except dns.rdataclass.UnknownRdataclass: - pass - try: - tip = dns.rdatatype.from_text(nizi[0]) - for i in [" ", "\t"]: - for j in [" ", "\t"]: - try: - datastart = line.index(i+nizi[0]+j)+len(i+nizi[0]+i) - except ValueError: - continue - break - else: - continue - break - nizi.pop(0) - except dns.rdatatype.UnknownRdatatype: - pass - if tip == None: - print(f"NAPAKA: na vrstici {lineno} ne najdem tipa zapisa. Vrstica je lahko bodisi komentar, ki se začne z ';', bodisi je v obliki IME [TTL={newconfig['t']}] [CLASS=IN] TIP PODATKI.") - print(f"Vsebina neveljavne vrstice: " + line) - sys.exit(1) - while line[datastart] in [" ", "\t"]: - datastart += 1 - data = line[datastart:] - if razred == None: - razred = dns.rdataclass.IN - if ttl == None: - ttl = newconfig["t"] - ime = dns.name.from_unicode(ime, dns.name.from_unicode(domena)).choose_relativity(dns.name.from_unicode(domena), True).to_unicode() - if tip == dns.rdatatype.SOA: - data = data.split() - data[2] = str(int(data[2])+newconfig["+"]) - data = " ".join(data) - tapl = (ttl, ime, komentar, None, razred, tip, data) - if komentar != "": - novikomentarji[ime + " " + tip.to_text(tip)] = komentar - if konec != "\t": - novikonci[ime] = konec - if not tapl in rrs: - print("+ " + komentar.replace("\n", "\n+ ") + ime + konec + str(ttl) + "\t" + razred.to_text(razred) + "\t" + tip.to_text(tip) + "\t" + data) - plus += 1 - update.add(ime, ttl, tip, data) - else: - rrs.remove(tapl) - komentar = "" - except IndexError: - break -obstoječ = "" # zadnji komentar -for komentar in config["c"].values(): - obstoječ += komentar -for rr in rrs: - print("- " + komentar.replace("\n", "\n- ") + rr[1] + konec + str(rr[0]) + "\t" + rr[4].to_text(rr[4]) + "\t" + rr[5].to_text(rr[5]) + "\t" + rr[6]) - minus += 1 - update.delete(rr[1], rr[5].to_text(rr[5]), rr[6]) -if obstoječ != komentar: - print("- " + "\n+ ".join(obstoječ.split("\n"))) - print("+ " + "\n+ ".join(komentar.split("\n"))) - plus += 1 - minus += 1 -novikomentarji["z"] = komentar -newconfig["c"] = novikomentarji -newconfig["i"] = novikonci -odziv = input(f"(-{minus}/+{plus}) Ali želite te spremembe poslati na strežnik? [Y/D/J/n] ") -if len(odziv) != 0 and odziv[0] in ["n", "N", "0", "f", "F"]: - print("Prekinjam. Nasvidenje!") - sys.exit(0) -jason = json.dumps(newconfig) -jasonsplit = " ".join(['"' + jason[i*255:i*255+255].replace("\\", "\\\\").replace('"', '\\"') + '"' for i in range(math.ceil(len(jason)/255))]) -update.replace("_urejevalnik", 1, dns.rdatatype.TXT, jasonsplit) -response = dns.query.tcp(update, naslov) -print("Poslal zahtevo. Odziv strežnika:") -print(response) diff --git a/skripti/zone_axfr.py b/skripti/zone_axfr.py new file mode 100755 index 0000000..81460a6 --- /dev/null +++ b/skripti/zone_axfr.py @@ -0,0 +1,86 @@ +#!/usr/bin/python3 +import dns.zone +import dns.resolver +import json +import sys +domena = sys.argv[1] +strežniki = [dns.resolver.resolve(domena, "SOA")[0].mname] +for i in dns.resolver.resolve(domena, "NS"): + strežniki.append(i.target) +naslovi = [] +for strežnik in strežniki: + for i in dns.resolver.resolve(strežnik, "AAAA"): + naslovi.append(i.address) + for i in dns.resolver.resolve(strežnik, "A"): + naslovi.append(i.address) +for naslov in naslovi: # opcijsko dodaj tule kakšen try catch + zone = None + zone = dns.zone.from_xfr(dns.query.xfr(naslov, domena)) + if zone != None: + break +config = None +try: + config = json.loads(b''.join(zone["_urejevalnik"].get_rdataset(dns.rdataclass.IN, dns.rdatatype.TXT)[0].strings).decode()) +except KeyError: + pass +except json.decoder.JSONDecodeError: + pass +if config == None: + berime = """; Dobrodošli v preprost urejevalnik DNS zapisov. +; Komentarji se shranijo v DNS strežnik in so javni. Morajo biti na samostojnih vrsticah. +; Te komentarje z navodili lahko izbrišete -- ne bodo se ponovno pojavili. +; Nove zapise naložite na strežnik z ukazom zone_update.py zonefile.db +; Zapise prenesete iz strežnika z ukazom zone_axfr.py domena > zonefile.db +; Prva vrstica je konfiguracijski zapis v JSON obliki. Naslednje podatke lahko spremenite: +; "t": privzeti TTL, ki se uporabi, če zapis v datoteki nima TTLja +; "+": koliko naj prištejem serijski številki pred nalaganjem na strežnik + +""" + config = {"v": 0, "d": domena, "c": {"@ SOA": berime}, "t": 1, "+": 100, "i": {}} +configout = config.copy() +del configout["c"] +del configout["i"] +print(f"{json.dumps(configout)}") +for r in zone.iterate_rdatas(): + if r[0].to_unicode() == "_urejevalnik" or r[2].rdtype in [dns.rdatatype.RRSIG, dns.rdatatype.NSEC, dns.rdatatype.NSEC3, dns.rdatatype.DNSKEY]: + continue + commentkey = r[0].to_unicode() + " " + r[2].rdtype.name + if commentkey in config["c"].keys(): + print(config["c"][commentkey], end="") + del config["c"][commentkey] + konec = "\t" + if r[0].to_unicode() in config["i"].keys(): + konec = config["i"][r[0].to_unicode()] + print(r[0].to_unicode(), end=konec) + if r[1] != config["t"]: + print(r[1], end="") + print("\t", end="") + if r[2].rdclass != dns.rdataclass.IN: + print(r[2].rdataclass.name, end="\t") + print(r[2].rdtype.name, end="\t") + if r[2].rdtype == dns.rdatatype.TXT: + prvič = True + for string in r[2].strings: + if prvič: + prvič = False + else: + print(" ", end="") + bajti = b'' + for char in string: + if char < ord(b' '): + bajti += b'\\' + ("%03d" % ord(char)).encode() + else: + bajti += bytes([char]) + niz = "" + for znak in bajti.replace(b'\\', b'\\\\').replace(b'"', b'\\"').decode('utf-8', errors='surrogateescape'): + if '\udc80' <= znak <= '\udcff': + niz += '\\'+("%03d" % (ord(znak)-0xdc00)) + else: + niz += znak + + print('"' + niz + '"', end="") + else: + print(r[2].to_text(), end="") + print() +for i in config["c"].items(): + print(i[1], end="") diff --git a/skripti/zone_update.py b/skripti/zone_update.py new file mode 100755 index 0000000..ead2c39 --- /dev/null +++ b/skripti/zone_update.py @@ -0,0 +1,174 @@ +#!/usr/bin/python3 +import dns.zone +import dns.resolver +import dns.update +import dns.tsigkeyring +import json +import sys +import math +with open(sys.argv[1], "r") as db: + lines = db.readlines() +newconfig = json.loads(lines.pop(0)[:-1]) +domena = newconfig["d"] +strežniki = [dns.resolver.resolve(domena, "SOA")[0].mname] +naslovi = [] +for strežnik in strežniki: + for i in dns.resolver.resolve(strežnik, "AAAA"): + naslovi.append(i.address) + for i in dns.resolver.resolve(strežnik, "A"): + naslovi.append(i.address) +for naslov in naslovi: # opcijsko dodaj tule kakšen try catch + zone = None + zone = dns.zone.from_xfr(dns.query.xfr(naslov, domena)) + if zone != None: + break +config = None +try: + config = json.loads(b''.join(zone["_urejevalnik"].get_rdataset(dns.rdataclass.IN, dns.rdatatype.TXT)[0].strings).decode()) +except KeyError: + pass +except json.decoder.JSONDecodeError: + pass +if config == None: + config = {"v": 0, "d": domena, "c": {}, "t": 1, "+": 100, "i": {}} +rrs = [] +for r in zone.iterate_rdatas(): + if r[0].to_unicode() == "_urejevalnik" or r[2].rdtype in [dns.rdatatype.RRSIG, dns.rdatatype.NSEC, dns.rdatatype.NSEC3, dns.rdatatype.DNSKEY]: + continue + commentkey = r[0].to_unicode() + " " + r[2].rdtype.name + komentar = "" + if commentkey in config["c"].keys(): + komentar = config["c"][commentkey] + del config["c"][commentkey] + konec = "\t" + if r[0].to_unicode() in config["i"].keys(): + konec = config["i"][r[0].to_unicode()] + vrednost = "" + if r[2].rdtype == dns.rdatatype.TXT: + for string in r[2].strings: + bajti = b'' + for char in string: + if char < ord(b' '): + bajti += b'\\' + ("%03d" % ord(char)).encode() + else: + bajti += bytes([char]) + niz = "" + for znak in bajti.replace(b'\\', b'\\\\').replace(b'"', b'\\"').decode('utf-8', errors='surrogateescape'): + if '\udc80' <= znak <= '\udcff': + niz += '\\'+("%03d" % (ord(znak)-0xdc00)) + else: + niz += znak + vrednost = '"' + niz + '"' + else: + vrednost = r[2].to_text() + rrs.append((r[1], r[0].to_unicode(), komentar, None, r[2].rdclass, r[2].rdtype, vrednost)) +komentar = "" +lineno = 1 +novikomentarji = {} +novikonci = {} +keyring = None +plus = 0 +minus = 0 +if len(sys.argv) == 3: + with open(sys.argv[2]) as file: + ključ = file.read() + keyring = dns.tsigkeyring.from_text({ključ.split()[ključ.split().index("key")+1].replace('"', "").replace(";", ""): ključ.split()[ključ.split().index("secret")+1].replace('"', "").replace(";", "")}) +update = dns.update.Update(domena, keyring=keyring) +while True: + try: + lineno += 1 + line = lines.pop(0)[:-1] # odstranimo zadnji \n, ki ga zraven da .readlines + if len(line.split()) == 0 or line[0] == ';' or line[0] == '#' or line[0] == '/': + komentar += line + "\n" + continue + ime = line.split()[0] + konec = "" + index = len(ime) + while line[index] in ["\t", " "]: + konec += line[index] + index += 1 + nizi = line.split()[1:] + tip = None + razred = None + ttl = None + while tip == None: + try: + ttl = int(nizi[0]) + nizi.pop(0) + except ValueError: + pass + try: + razred = dns.rdataclass.from_text(nizi[0]) + nizi.pop(0) + except dns.rdataclass.UnknownRdataclass: + pass + try: + tip = dns.rdatatype.from_text(nizi[0]) + for i in [" ", "\t"]: + for j in [" ", "\t"]: + try: + datastart = line.index(i+nizi[0]+j)+len(i+nizi[0]+i) + except ValueError: + continue + break + else: + continue + break + nizi.pop(0) + except dns.rdatatype.UnknownRdatatype: + pass + if tip == None: + print(f"NAPAKA: na vrstici {lineno} ne najdem tipa zapisa. Vrstica je lahko bodisi komentar, ki se začne z ';', bodisi je v obliki IME [TTL={newconfig['t']}] [CLASS=IN] TIP PODATKI.") + print(f"Vsebina neveljavne vrstice: " + line) + sys.exit(1) + while line[datastart] in [" ", "\t"]: + datastart += 1 + data = line[datastart:] + if razred == None: + razred = dns.rdataclass.IN + if ttl == None: + ttl = newconfig["t"] + ime = dns.name.from_unicode(ime, dns.name.from_unicode(domena)).choose_relativity(dns.name.from_unicode(domena), True).to_unicode() + if tip == dns.rdatatype.SOA: + data = data.split() + data[2] = str(int(data[2])+newconfig["+"]) + data = " ".join(data) + tapl = (ttl, ime, komentar, None, razred, tip, data) + if komentar != "": + novikomentarji[ime + " " + tip.to_text(tip)] = komentar + if konec != "\t": + novikonci[ime] = konec + if not tapl in rrs: + print("+ " + komentar.replace("\n", "\n+ ") + ime + konec + str(ttl) + "\t" + razred.to_text(razred) + "\t" + tip.to_text(tip) + "\t" + data) + plus += 1 + update.add(ime, ttl, tip, data) + else: + rrs.remove(tapl) + komentar = "" + except IndexError: + break +obstoječ = "" # zadnji komentar +for komentar in config["c"].values(): + obstoječ += komentar +for rr in rrs: + print("- " + komentar.replace("\n", "\n- ") + rr[1] + konec + str(rr[0]) + "\t" + rr[4].to_text(rr[4]) + "\t" + rr[5].to_text(rr[5]) + "\t" + rr[6]) + minus += 1 + update.delete(rr[1], rr[5].to_text(rr[5]), rr[6]) +if obstoječ != komentar: + print("- " + "\n+ ".join(obstoječ.split("\n"))) + print("+ " + "\n+ ".join(komentar.split("\n"))) + plus += 1 + minus += 1 +novikomentarji["z"] = komentar +newconfig["c"] = novikomentarji +newconfig["i"] = novikonci +odziv = input(f"(-{minus}/+{plus}) Ali želite te spremembe poslati na strežnik? [Y/D/J/n] ") +if len(odziv) != 0 and odziv[0] in ["n", "N", "0", "f", "F"]: + print("Prekinjam. Nasvidenje!") + sys.exit(0) +jason = json.dumps(newconfig) +jasonsplit = " ".join(['"' + jason[i*255:i*255+255].replace("\\", "\\\\").replace('"', '\\"') + '"' for i in range(math.ceil(len(jason)/255))]) +update.replace("_urejevalnik", 1, dns.rdatatype.TXT, jasonsplit) +response = dns.query.tcp(update, naslov) +print("Poslal zahtevo. Odziv strežnika:") +print(response) diff --git "a/skripti/\305\276" "b/skripti/\305\276" new file mode 100644 index 0000000..d18de36 --- /dev/null +++ "b/skripti/\305\276" @@ -0,0 +1,36 @@ +#!/bin/bash +# $1 naj bo icecast host kruljo.radiostudent.si +# $2 naj bo icecast http port 8000 +# $3 naj bo icecast endpoint /ehiq +# $4 naj bo končnica datotek .mp3 +# v CWD delam imenike in datoteke in sem glede tega kompatibilen z earhornom: +# Posnetek 2024/06/03/202136.mp3 se začne 2024-06-03T20:21:36 vedno UTC. +# Posnetkov ne splittam na uro. Posnetek se splitta le takrat, ko se zgodi napaka (stream crkne) -- takrat začnem pisati v novo datoteko +# požvižgam se na vsebino datotek. zame so to le bajti. v tem nisem earhornski. +host=$1 +port=$2 +endpoint=$3 +kon=$4 +mistakes=0 +set -xeuo pipefail +while : +do + filename=`date --utc +%Y/%m/%d/%H%m%S$kon` + mkdir -p `cut -d/ -f1-3 <<<$filename` + start=$SECONDS + set +e + nc $host $port <<<"GET $endpoint HTTP/1.0"$'\r\n\r' > $filename + koda=$? + set -e + echo TCP PREKINJEN! ZAČENJAM NOV POSNETEK! IZHODNA KODA nc je $koda, datum je `date` + if [ $(($SECONDS-$start)) -lt 300 ] + then + mistakes=$(($mistakes+1)) + if [ $mistakes -gt 3 ] + then + sleep $((2**($mistakes-3))) + fi + else + mistakes=0 + fi +done diff --git "a/\305\241ola/ds2/teor.lyx" "b/\305\241ola/ds2/teor.lyx" index c0fe332..2d03ffc 100644 --- "a/\305\241ola/ds2/teor.lyx" +++ "b/\305\241ola/ds2/teor.lyx" @@ -431,13 +431,10 @@ S , kot to naredi \family typewriter -bash -\end_layout - -\end_inset - -. - Nekateri bi +bash. + +\family default +Nekateri bi \begin_inset Formula $\left\{ 1..n\right\} $ \end_inset @@ -445,7 +442,12 @@ bash \begin_inset Formula $\left[n\right]$ \end_inset -.. +. +\end_layout + +\end_inset + +. Dolžina sprehoda je število prehojenih povezav. Sprehod je \series bold @@ -7532,11 +7534,7 @@ Naj bo \end_inset in -\begin_inset Formula $\left(a+I\right)\cdot$ -\end_inset - -' -\begin_inset Formula $\left(b+I\right)=a\cdot b+I$ +\begin_inset Formula $\left(a+I\right)\cdot'\left(b+I\right)=a\cdot b+I$ \end_inset . diff --git "a/\305\241ola/p2/dn/DN09b_63230317.c" "b/\305\241ola/p2/dn/DN09b_63230317.c" new file mode 100644 index 0000000..daca2bf --- /dev/null +++ "b/\305\241ola/p2/dn/DN09b_63230317.c" @@ -0,0 +1,48 @@ +#include +#include +#include +int next (bool * s, int l) { + bool hit0 = false; + bool hit1after0 = false; + int end1count = 0; + int end1 = l-1; + for (int i = l-1; i >= 0; i--) { + if (!s[end1]) + end1--; + if (!hit0 && s[i] == 1) + end1count++; + if (!s[i]) + hit0 = true; + if (hit0 && s[i]) + hit1after0 = true; + } + if (end1 == -1) { // prazen vhod, sedaj 1 bit + for (int i = 0; i < l; i++) + s[i] = false; + s[0] = true; + return 1; + } + if (!hit0) + return len+1; // konec + if (!hif1after0) { // inc št enic + for (int i = 0; i < l; i++) { + s[i] = false; + if (i < end1count) + s[i] = true; + } + return end1count; + } +} +int main (void) { + int s, g, m; + scanf("%d", &s); + char * i[s]; + char * r[s]; + for (int i = 0; i < s; i++) + scanf("%ms %ms", &i[s], &r[s]); + scanf("%d", &g); + char * gl[g]; + for (int i = 0; i < s; i++) + scanf("%ms", &gl[s]); + bool samost[s]; +} -- cgit v1.2.3