Compare commits
No commits in common. "master" and "master" have entirely different histories.
38
equinox.py
38
equinox.py
|
@ -1,38 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from urllib.request import urlopen
|
|
||||||
from subprocess import check_output
|
|
||||||
|
|
||||||
atf = '%a %b %d %H:%M:00 %Y'
|
|
||||||
|
|
||||||
with urlopen('https://en.wikipedia.org/w/index.php?title=Template:Solstice-equinox') as web:
|
|
||||||
soup = BeautifulSoup(web.read(), 'html.parser')
|
|
||||||
|
|
||||||
table = soup.find('table', attrs={'class': 'wikitable'}).find('tbody')
|
|
||||||
dates = dict()
|
|
||||||
today = datetime.now()
|
|
||||||
|
|
||||||
for tr in table.find_all('tr'):
|
|
||||||
try:
|
|
||||||
year = int(tr.find('th').text.strip())
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
times = [td.text.strip() for td in tr.find_all('td')]
|
|
||||||
for i, m, text in ((0, 3, 'March equinox'), (2, 6, 'June solstice'), (4, 9, 'September equinox'), (6, 12, 'December solstice')):
|
|
||||||
hour, minute = map(int, times[i+1].split(':'))
|
|
||||||
date = datetime(year=year, month=m, day=int(times[i]), hour=hour, minute=minute)
|
|
||||||
if date > today:
|
|
||||||
dates[date.strftime(atf)] = (date.strftime('%H:%M %B %d %Y'), text)
|
|
||||||
|
|
||||||
atd = filter(None, check_output(['atq', '-q', 's']).decode().strip().split('\n'))
|
|
||||||
atd = set(' '.join(d.split('\t')[1].split(' ')[:-2]) for d in atd)
|
|
||||||
|
|
||||||
for date, text in map(dates.get, set(dates) - atd):
|
|
||||||
text = '/home/zgrep/offtopiabday/happy ' + text
|
|
||||||
print(f'Scheduling {text} at {date}.')
|
|
||||||
try:
|
|
||||||
check_output(['at', '-q', 's', date], universal_newlines=True, input=text)
|
|
||||||
except:
|
|
||||||
print('Failed.')
|
|
62
holi.py
62
holi.py
|
@ -1,62 +0,0 @@
|
||||||
#!/usr/bin/env python3
|
|
||||||
|
|
||||||
from datetime import datetime
|
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
from urllib.request import urlopen
|
|
||||||
from subprocess import check_output
|
|
||||||
|
|
||||||
atf = '%a %b %d %H:%M:00 %Y'
|
|
||||||
|
|
||||||
with urlopen('https://en.wikipedia.org/w/index.php?title=Holi') as web:
|
|
||||||
soup = BeautifulSoup(web.read(), 'html.parser')
|
|
||||||
|
|
||||||
table = soup.find('table', attrs={'class': 'infobox'}).find('tbody')
|
|
||||||
dates = dict()
|
|
||||||
today = datetime.now()
|
|
||||||
|
|
||||||
months = '''
|
|
||||||
January
|
|
||||||
February
|
|
||||||
March
|
|
||||||
April
|
|
||||||
May
|
|
||||||
June
|
|
||||||
July
|
|
||||||
August
|
|
||||||
September
|
|
||||||
October
|
|
||||||
November
|
|
||||||
December
|
|
||||||
'''.strip().split()
|
|
||||||
|
|
||||||
for tr in table.find_all('tr'):
|
|
||||||
try:
|
|
||||||
year = tr.find('th').text.strip()
|
|
||||||
if not year.endswith('date'):
|
|
||||||
continue
|
|
||||||
year = int(year[:-4].strip())
|
|
||||||
|
|
||||||
daymonth = tr.find('td')
|
|
||||||
for e in daymonth.find_all('sup'):
|
|
||||||
e.extract()
|
|
||||||
daymonth = daymonth.text.strip().split()
|
|
||||||
day = int(daymonth[0])
|
|
||||||
month = months.index(daymonth[1]) + 1
|
|
||||||
except:
|
|
||||||
continue
|
|
||||||
date = datetime(year=year, month=month, day=day, hour=0, minute=0)
|
|
||||||
if date > today:
|
|
||||||
dates[date.strftime(atf)] = date.strftime('%H:%M %B %d %Y')
|
|
||||||
|
|
||||||
at_letter = 'i'
|
|
||||||
|
|
||||||
atd = filter(None, check_output(['atq', '-q', at_letter]).decode().strip().split('\n'))
|
|
||||||
atd = set(' '.join(d.split('\t')[1].split(' ')[:-2]) for d in atd)
|
|
||||||
|
|
||||||
for date in map(dates.get, set(dates) - atd):
|
|
||||||
text = '/home/zgrep/offtopiabday/exclaimheart Holi mubārāk'
|
|
||||||
print(f'Scheduling {text} at {date}.')
|
|
||||||
try:
|
|
||||||
check_output(['at', '-q', at_letter, date], universal_newlines=True, input=text)
|
|
||||||
except:
|
|
||||||
print('Failed.')
|
|
12
xplace/x.py
12
xplace/x.py
|
@ -1,6 +1,5 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from lark import Lark, Transformer, ParseError, Tree
|
from lark import Lark, Transformer, ParseError, Tree
|
||||||
from random import shuffle
|
|
||||||
|
|
||||||
parser = Lark(r'''
|
parser = Lark(r'''
|
||||||
DIGIT : /[0-9]/
|
DIGIT : /[0-9]/
|
||||||
|
@ -13,9 +12,9 @@ parser = Lark(r'''
|
||||||
| bracketliteral "-" bracketliteral
|
| bracketliteral "-" bracketliteral
|
||||||
brackets : "[" range+ "]" -> either
|
brackets : "[" range+ "]" -> either
|
||||||
|
|
||||||
?achar : /[^\\\[\]\{\}\(\)\|\^~\?!¿]/
|
char : /[^\\\[\]\{\}\(\)\|\^~\?!]/
|
||||||
| "\\" /\D/
|
| "\\" /\D/
|
||||||
char : achar?
|
| //
|
||||||
|
|
||||||
numrange : DIGITS
|
numrange : DIGITS
|
||||||
| DIGITS "-" DIGITS [ "*" DIGITS ] [ "+" DIGITS ]
|
| DIGITS "-" DIGITS [ "*" DIGITS ] [ "+" DIGITS ]
|
||||||
|
@ -24,7 +23,6 @@ parser = Lark(r'''
|
||||||
?concat_func : unit
|
?concat_func : unit
|
||||||
| concat_func "{" DIGITS "}" -> concat_repeat
|
| concat_func "{" DIGITS "}" -> concat_repeat
|
||||||
| concat_func "?" -> zero_or_one
|
| concat_func "?" -> zero_or_one
|
||||||
| concat_func "¿" -> random
|
|
||||||
| concat_func "~" -> reverse
|
| concat_func "~" -> reverse
|
||||||
| concat_func "~" NUMBER -> roll
|
| concat_func "~" NUMBER -> roll
|
||||||
| concat_func "~{" NUMBER ["," DIGITS] "}" -> roll
|
| concat_func "~{" NUMBER ["," DIGITS] "}" -> roll
|
||||||
|
@ -46,7 +44,7 @@ parser = Lark(r'''
|
||||||
| choice ("|" choice_func)+ -> either
|
| choice ("|" choice_func)+ -> either
|
||||||
|
|
||||||
?parens : "(" choice ")"
|
?parens : "(" choice ")"
|
||||||
''', start='choice', priority='invert')
|
''', start='choice', ambiguity='resolve__antiscore_sum')
|
||||||
|
|
||||||
class Expand(Transformer):
|
class Expand(Transformer):
|
||||||
def __init__(self, amp=None):
|
def __init__(self, amp=None):
|
||||||
|
@ -76,10 +74,6 @@ class Expand(Transformer):
|
||||||
def zero_or_one(self, args):
|
def zero_or_one(self, args):
|
||||||
return self.either([[''], args[0]])
|
return self.either([[''], args[0]])
|
||||||
|
|
||||||
def random(self, args):
|
|
||||||
shuffle(args[0])
|
|
||||||
return args[0]
|
|
||||||
|
|
||||||
def either(self, args):
|
def either(self, args):
|
||||||
result = []
|
result = []
|
||||||
for x in args:
|
for x in args:
|
||||||
|
|
Loading…
Reference in New Issue