Skip to content

Commit 87f193d

Browse files
authored
Raspberry script & minor fixes (#37)
* Github Actions badge * python script to update raspberry * fix lock not released on unknown error
1 parent 81704d3 commit 87f193d

5 files changed

Lines changed: 48 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JackBot
22

3-
[![CircleCI](https://img.shields.io/circleci/build/github/dcr-guys/JackBot)](https://circleci.com/gh/dcr-guys/JackBot)
3+
[![Actions Status](https://github.com/dcr-guys/JackBot/workflows/Python%20application%20tests/badge.svg)](https://github.com/dcr-guys/JackBot/actions)
44
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/e0eb1aab12184d0b98bee7f1729ecffa)](https://www.codacy.com/manual/rodrigondec/JackBot?utm_source=github.com&utm_medium=referral&utm_content=rodrigondec/JackBot&utm_campaign=Badge_Grade)
55

6-
JackBot is a Ticket Splitting Sessions watcher/notifier teleram bot
6+
JackBot is a Ticket Splitting Sessions watcher/notifier telegram bot

db/ticket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,6 @@ def get_last(cls):
6161
last_ticket_price = cls._fetch_new_ticket_price()
6262
finally:
6363
last_ticket_price.save()
64+
cls.lock.release()
6465

65-
cls.lock.release()
6666
return last_ticket_price

sws/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ def on_message(ws: WebSocketApp, data):
8282
except DuplicatedUpdateMessageError as e:
8383
logger.info(f"Supress {e} for creating {UpdateMessage} "
8484
f"from {data} on {sws}")
85+
except Exception as e:
86+
logger.error(e)
87+
finally:
88+
if sws.lock.locked():
89+
sws.lock.release()
8590

8691
@staticmethod
8792
def on_error(ws, error: Exception):

tests/db/test_update_message.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from unittest import TestCase, mock
22

33
import pytest
4+
import pendulum
45

56
from tests.fixtures import mongo # noqa F401
67
from db.update_message import UpdateMessage, Session, Amount
@@ -67,10 +68,12 @@ def test_equal_false(self):
6768
self.assertFalse(instance.equal(other))
6869

6970
def test_get_last_by_subject(self):
70-
UpdateMessage(self.subject, [Session('test',
71-
[Amount(1000000000)])]).save()
71+
UpdateMessage(self.subject,
72+
[Session('test', [Amount(1000000000)])],
73+
pendulum.yesterday()).save()
7274
other = UpdateMessage(self.subject,
73-
[Session('test', [Amount(1100000000)])]).save()
75+
[Session('test', [Amount(1100000000)])],
76+
pendulum.today()).save()
7477

7578
last = UpdateMessage.get_last_by_subject(self.subject)
7679
self.assertEqual(other, last)

update_raspberry.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import requests
2+
import json
3+
import tarfile
4+
import subprocess
5+
6+
releases_url = "https://api.github.com/repos/dcr-guys/JackBot/releases"
7+
releases_response = requests.get(releases_url)
8+
releases_response.data = json.loads(releases_response.content)
9+
10+
latest = releases_response.data[0]
11+
latest_tarball = requests.get(latest.get('tarball_url'))
12+
latest_name = latest.get('name')
13+
14+
base_dir = f"./{latest_name}/"
15+
tarfile_name = f"{base_dir}{latest_name}.tar.gz"
16+
17+
subprocess.run(["mkdir", base_dir])
18+
19+
with open(tarfile_name, 'wb') as file:
20+
file.write(latest_tarball.content)
21+
22+
with tarfile.open(tarfile_name) as tar:
23+
subfolder_name = tar.firstmember.name
24+
tar.extractall(base_dir)
25+
26+
source_dir = f"{base_dir}/{subfolder_name}/"
27+
dest_dir = "./"
28+
subprocess.run(['rsync', '-av', source_dir, dest_dir])
29+
30+
subprocess.run(['rm', '-rf', base_dir])
31+
32+
subprocess.run(['make', 'docker.arm.down'])
33+
subprocess.run(['make', 'docker.arm.build'])
34+
subprocess.run(['make', 'docker.arm.up'])

0 commit comments

Comments
 (0)