Skip to content

Commit

Permalink
Fix #100 and use f-strings!
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayak-mehta committed May 23, 2020
1 parent 8e677b1 commit 5d5a917
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 31 deletions.
3 changes: 1 addition & 2 deletions conrad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@


CONRAD_HOME = get_app_dir("conrad")
SQL_ALCHEMY_CONN = "sqlite:///{}/conrad.db".format(CONRAD_HOME)

SQL_ALCHEMY_CONN = f"sqlite:///{CONRAD_HOME}/conrad.db"

if not os.path.exists(CONRAD_HOME):
os.makedirs(CONRAD_HOME)
4 changes: 2 additions & 2 deletions conrad/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
def generate_version(version, prerelease=None, revision=None):
version_parts = [".".join(map(str, version))]
if prerelease is not None:
version_parts.append("-{}".format(prerelease))
version_parts.append(f"-{prerelease}")
if revision is not None:
version_parts.append(".{}".format(revision))
version_parts.append(f".{revision}")
return "".join(version_parts)


Expand Down
57 changes: 33 additions & 24 deletions conrad/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def _show(ctx, *args, **kwargs):
if tag:
filters.append(Event.tags.contains(tag))
if name:
filters.append(Event.name.ilike("%{}%".format(name)))
filters.append(Event.name.ilike(f"%{name}%"))
if date:
date_filters = []
for d in date:
Expand All @@ -273,9 +273,9 @@ def _show(ctx, *args, **kwargs):
if location:
filters.append(
sqlalchemy.or_(
Event.city.ilike("%{}%".format(location)),
Event.state.ilike("%{}%".format(location)),
Event.country.ilike("%{}%".format(location)),
Event.city.ilike(f"%{location}%"),
Event.state.ilike(f"%{location}%"),
Event.country.ilike(f"%{location}%"),
)
)

Expand Down Expand Up @@ -341,27 +341,37 @@ def _remind(ctx, *args, **kwargs):

for reminder, __ in reminders:
start = dt.datetime.now()

if reminder.cfp_open:
delta_days = (reminder.cfp_end_date - start).days
days_left = "{} days left to cfp deadline!".format(delta_days)
cfp_days_left = (reminder.cfp_end_date - start).days
event_days_left = (reminder.start_date - start).days

if reminder.cfp_open and cfp_days_left >= 0:
days_left = cfp_days_left
days_left_output = f"{days_left} days left to cfp deadline!"
elif event_days_left >= 0:
days_left = event_days_left
days_left_output = f"{days_left} days left!"
else:
delta_days = (reminder.start_date - start).days
days_left = "{} days left!".format(delta_days)

if delta_days > 30:
days_left = Fore.GREEN + Style.BRIGHT + days_left + Style.RESET_ALL
elif delta_days <= 30 and delta_days > 10:
days_left = Fore.YELLOW + Style.BRIGHT + days_left + Style.RESET_ALL
elif delta_days <= 10:
days_left = Fore.RED + Style.BRIGHT + days_left + Style.RESET_ALL
days_left = -1
days_left_output = "Event ended."

if days_left > 30:
style = f"{Fore.GREEN}{Style.BRIGHT}"
elif days_left <= 30 and days_left > 10:
style = f"{Fore.YELLOW}{Style.BRIGHT}"
elif days_left <= 10 and days_left > 0:
style = f"{Fore.RED}{Style.BRIGHT}"
else:
style = ""
days_left_output = (
f"{style}{days_left_output}{Style.RESET_ALL}"
)

reminders_output.append(
[
reminder.id,
reminder.name,
reminder.start_date.strftime("%Y-%m-%d"),
days_left,
days_left_output,
]
)
session.close()
Expand Down Expand Up @@ -435,10 +445,9 @@ def _import(ctx, *args, **kwargs):
events.append(e)
removed = len(old_events) - len(events)
s = "s" if removed > 1 else ""
click.echo("Removed {} old event{}!".format(removed, s))
click.echo(f"Removed {removed} old event{s}!")

# TODO: drop events with end date < now
# TODO: update cfp to false when cfp end date < now
# TODO: update cfp to false when cfp_end_date < now
pattern = "[0-9]"
new_events = []
for ie in input_events:
Expand All @@ -454,15 +463,15 @@ def _import(ctx, *args, **kwargs):
input_event_name, event_name
)
if similarity > 0.9:
click.echo("Updating {}".format(e["name"]))
click.echo(f"Updating {e['name']}")
e.update(ie)
match = True
if not match:
click.echo("Adding {}".format(ie["name"]))
click.echo(f"Adding {ie['name']}")
new_events.append(ie)
events.extend(new_events)

s = "s" if len(new_events) > 1 else ""
click.echo("Added {} new event{}!".format(len(new_events), s))
click.echo(f"Added {len(new_events)} new event{s}!")
with open(EVENTS_PATH, "w") as f:
f.write(json.dumps(events, indent=4, sort_keys=True))
2 changes: 1 addition & 1 deletion crawlers/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def main():
Crawler = eval(crawler[0])
c = Crawler()
c.get_events()
c.export("data/{}_events.json".format(filename))
c.export(f"data/{filename}_events.json")
else:
print("Crawler not found!")

Expand Down
2 changes: 1 addition & 1 deletion crawlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def export(self, filename):
v.validate(event)
if v.errors:
for key, val in v.errors.items():
print("{} - {}: {}".format(event["name"], key, val))
print(f"{event['name']} - {key}: {val}")

with open(filename, "w") as f:
f.write(json.dumps(self.events, indent=4, sort_keys=True))
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def setup_package():
# Trove classifiers
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
],
Expand Down

0 comments on commit 5d5a917

Please sign in to comment.