Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/ikhal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from khal.cli import main_ikhal

if __name__ == "__main__":
main_ikhal()
if _name_ == "_main_":
    main_ikhal()
4 changes: 2 additions & 2 deletions bin/khal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
from khal.cli import main_khal

if __name__ == "__main__":
main_khal()
if _name_ == "_main_":
    main_khal()
59 changes: 39 additions & 20 deletions khal/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,25 +326,42 @@ def khal_list(
def new_interactive(collection, calendar_name, conf, info, location=None,
categories=None, repeat=None, until=None, alarms=None,
format=None, json=None, env=None, url=None):
info: EventCreationTypes
try:
info = parse_datetime.eventinfofstr(
info, conf['locale'],
default_event_duration=conf['default']['default_event_duration'],
default_dayevent_duration=conf['default']['default_dayevent_duration'],
adjust_reasonably=True,
)
except DateTimeParseError:
# Vérifiez si info est une chaîne ou un dictionnaire, puis initialisez en conséquence
if isinstance(info, dict):
info_string = f"{info.get('summary', '')} {info.get('datetime_range', '')}"
elif isinstance(info, str):
info_string = info
info = {} # Réinitialisez `info` en dictionnaire après conversion
else:
info_string = ""
info = {}

while True:
try:
# Passez une chaîne correctement formatée à `eventinfofstr`
parsed_info = parse_datetime.eventinfofstr(
info_string.strip(),
conf['locale'],
default_event_duration=conf['default']['default_event_duration'],
default_dayevent_duration=conf['default']['default_dayevent_duration'],
adjust_reasonably=True,
)
info.update(parsed_info) # Mettez à jour `info` avec les données parsées
break # Sortir de la boucle si tout est valide
except DateTimeParseError as e:
echo(f"Error parsing information: {e}. Please correct the fields.")
summary = prompt('summary', default=info.get('summary', '')).strip()
datetime_range = prompt('datetime range', default=info.get('datetime_range', '')).strip()
info_string = f"{summary} {datetime_range}"

while True:
summary = info.get('summary')
if not summary:
summary = None
info['summary'] = prompt('summary', default=summary)
if info['summary']:
break
echo("a summary is required")
echo("A summary is required.")

while True:
range_string = None
Expand All @@ -353,14 +370,16 @@ def new_interactive(collection, calendar_name, conf, info, location=None,
end_string = info["dtend"].strftime(conf['locale']['datetimeformat'])
range_string = start_string + ' ' + end_string
daterange = prompt("datetime range", default=range_string)
start, end, allday = parse_datetime.guessrangefstr(
daterange, conf['locale'], adjust_reasonably=True)
info['dtstart'] = start
info['dtend'] = end
info['allday'] = allday
if info['dtstart'] and info['dtend']:
try:
start, end, allday = parse_datetime.guessrangefstr(
daterange, conf['locale'], adjust_reasonably=True
)
info['dtstart'] = start
info['dtend'] = end
info['allday'] = allday
break
echo("invalid datetime range")
except ValueError:
echo("Invalid datetime range, please try again.")

while True:
tz = info.get('timezone') or conf['locale']['default_timezone']
Expand All @@ -370,9 +389,9 @@ def new_interactive(collection, calendar_name, conf, info, location=None,
info['timezone'] = tz
break
except pytz.UnknownTimeZoneError:
echo("unknown timezone")
echo("Unknown timezone, please enter a valid timezone.")

info['description'] = prompt("description (or 'None')", default=info.get('description'))
info['description'] = prompt("description (or 'None')", default=info.get('description', ''))
if info['description'] == 'None':
info['description'] = ''

Expand All @@ -394,7 +413,7 @@ def new_interactive(collection, calendar_name, conf, info, location=None,
calendar_name=calendar_name,
json=json,
)
echo("event saved")
echo("Event saved.")

term_width, _ = get_terminal_size()
edit_event(event, collection, conf['locale'], width=term_width)
Expand Down
41 changes: 36 additions & 5 deletions khal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,45 @@ def fmt(rows):


CONTENT_ATTRIBUTES = ['start', 'start-long', 'start-date', 'start-date-long',
'start-time', 'end', 'end-long', 'end-date', 'end-date-long', 'end-time',
'duration', 'start-full', 'start-long-full', 'start-date-full',
'start-date-long-full', 'start-time-full', 'end-full', 'end-long-full',
'end-date-full', 'end-date-long-full', 'end-time-full', 'duration-full',
'start-style', 'end-style', 'to-style', 'start-end-time-style',
'end-necessary', 'end-necessary-long', 'repeat-symbol', 'repeat-pattern',
'title', 'organizer', 'description', 'location', 'all-day', 'categories',
'uid', 'url', 'calendar', 'calendar-color', 'status', 'cancelled']
'uid', 'url', 'calendar', 'calendar-color', 'status', 'cancelled', 'attendees']



def json_formatter(fields):
"""Create a formatter that formats events in JSON."""
if len(fields) == 1 and fields[0] == 'all':
fields = CONTENT_ATTRIBUTES

def fmt(rows):
single = isinstance(rows, dict)
if single:
rows = [rows]

filtered = []
for row in rows:
row['attendees'] = row.get('attendees', '') # Ajout d'une valeur par défaut
f = dict(filter(lambda e: e[0] in fields and e[0] in CONTENT_ATTRIBUTES, row.items()))

if f.get('repeat-symbol', '') != '':
f["repeat-symbol"] = f["repeat-symbol"].strip()
if f.get('status', '') != '':
f["status"] = f["status"].strip()
if f.get('cancelled', '') != '':
f["cancelled"] = f["cancelled"].strip()

filtered.append(f)

results = [json.dumps(filtered, ensure_ascii=False)]

if single:
return results[0]
else:
return results
return fmt

"""Create a formatter that formats events in JSON."""

if len(fields) == 1 and fields[0] == 'all':
Expand All @@ -239,7 +267,10 @@ def fmt(rows):

filtered = []
for row in rows:
print(f"Processing row: {row}") # Affiche les données brutes
row['attendees'] = row.get('attendees', '')
f = dict(filter(lambda e: e[0] in fields and e[0] in CONTENT_ATTRIBUTES, row.items()))
print(f"Filtered row: {f}") # Affiche les données filtrées

if f.get('repeat-symbol', '') != '':
f["repeat-symbol"] = f["repeat-symbol"].strip()
Expand Down
1 change: 1 addition & 0 deletions myenv/bin/python
1 change: 1 addition & 0 deletions myenv/bin/python3
1 change: 1 addition & 0 deletions myenv/bin/python3.11
1 change: 1 addition & 0 deletions myenv/lib64
5 changes: 5 additions & 0 deletions myenv/pyvenv.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
home = /usr/bin
include-system-site-packages = false
version = 3.11.2
executable = /usr/bin/python3.11
command = /usr/bin/python3 -m venv /home/bini/khal/myenv