Skip to content

Commit

Permalink
updates from the last deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
anandology committed Dec 18, 2024
1 parent 17d62b1 commit b696327
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 41 deletions.
6 changes: 5 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def app_page(name):
abort(404)
if app.name != name:
return redirect(f"/{app.name}")

site = Site(app.name)
status = site.get_status()
app.update_status(status)
return render_template("app.html", app=app, tasks=TASKS)

@app.route("/<name>/deploy", methods=["POST"])
Expand All @@ -52,4 +56,4 @@ def app_deploy(name):
return jsonify(status)

if __name__ == "__main__":
app.run()
app.run(port=5050)
2 changes: 1 addition & 1 deletion db.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def _update(self, **kwargs):
db.update("app", **kwargs, where="id=$id", vars={"id": self.id})

def update_score(self):
rows = db.where("task", app_id=self.id).list()
rows = db.where("task", app_id=self.id, status='pass').list()
score = len(rows)
self._update(score=score)

Expand Down
29 changes: 23 additions & 6 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ def login(self, email):

def sync(self):
try:
hamr.sync_app(self.name)
#hamr.sync_app(self.name)
pass
except HamrError as e:
return HamrResponse(ok=False, message=str(e))

Expand Down Expand Up @@ -167,6 +168,8 @@ def validate(self, site):
except CheckFailed as e:
return status.fail(str(e))
except Exception as e:
import traceback
traceback.print_exc()
return status.error(str(e))

def do_validate(self, site):
Expand Down Expand Up @@ -327,12 +330,26 @@ def do_validate(self, site):
response = site.post("/book-ticket", data=data)
response.raise_for_status()


q = """SELECT * FROM booking ORDER BY id DESC LIMIT 1"""
result = site.query(q)
if not result:
raise CheckFailed("Could not find any bookings")

row = result[0]


for k in "train_number ticket_class date passenger_name passenger_email".split():
if k not in row:
raise CheckFailed(f"Missing {k!r} column in table booking")

q = """
SELECT
train_number, ticket_class, date,
from_station_code, to_station_code,
passenger_name, passenger_email
FROM booking
b.train_number, b.ticket_class, b.date,
b.passenger_name, b.passenger_email,
t.from_station_code, t.to_station_code
FROM booking b
JOIN train t ON b.train_number=t.number
ORDER BY id DESC
LIMIT 1
"""
Expand Down Expand Up @@ -389,7 +406,7 @@ def __init__(self, bookings):
self.passenger_email = "[email protected]"

def get_bookings_from_html(self, html):
soup = BeautifulSoup(html)
soup = BeautifulSoup(html, "lxml")
booking_cards = soup.find_all("div", class_="card")
for card in booking_cards:
card_header = card.find("div", class_="card-header").get_text()
Expand Down
32 changes: 0 additions & 32 deletions tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,6 @@ description: |
and passenger details and books a ticket by adding an entry
in the database table.
After booking a ticket, the number of available seats for that
train in the booked ticket class should be reduced by one.
File: `rajdhani/db.py` <br>
Function: `book_ticket`
checks:
Expand All @@ -300,35 +297,6 @@ checks:
date: "2022-12-01"


---
name: email-conformation
title: Send an email to confirm the successful booking
description: |
Send an email to the passenger confirming the reservation.
You can use the SMTP credentials from `config.py` to do that.
The booking argument is a dict with keys: `id`, `passenger_name`,
`passenger_email`, `train_number`, `train_name`, `ticket_class`, and `date`.
Note: For testing locally, you can install the
[aiosmtpd](https://aiosmtpd.readthedocs.io/en/latest/) package with pip
and start an SMTP server on port 8025 with `python3 -m aiosmtpd -n`.
File: `rajdhani/notifications.py` <br>
Function: `send_booking_confirmation`
checks:
- check_ticket_confirmation_email:
train: "12028"
ticket_class: "CC"
date: "2022-09-30"
passenger_name: "Eva Lu Ator"
passenger_email: "[email protected]"
- check_ticket_confirmation_email:
train: "16227"
ticket_class: "FC"
date: "2022-09-28"
passenger_name: "Lem E Tweakit"
passenger_email: "[email protected]"
---
name: login-and-trips
title: Enable login and show trips for the user
Expand Down
4 changes: 3 additions & 1 deletion templates/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ <h1 class="mb-0">{{app.name}}</h1>
<a href="https://{{ app.name }}.rajdhani.pipal.in" class="text-decoration-none" target="_blank">
Visit website
</a>
<!--
| <a href="https://github.com/{{app.name}}/rajdhani">Github</a>
-->
</div>
<div>{{app.score}} tasks completed | Current Task: {{ app.current_task }} | Last updated {{datestr(app.last_updated) }}</div>
</div>
Expand Down Expand Up @@ -93,7 +95,7 @@ <h5>Checks</h5>

<div class="my-3">
<h2>Change Log</h2>
{% for entry in app.get_changelog() %}
{% for entry in app.get_changelog()[:10] %}
<div>{{datestr(entry.timestamp)}} - {{entry.type}} - {{entry.message}}</div>
{% endfor %}
</div>
Expand Down

0 comments on commit b696327

Please sign in to comment.