Skip to content

Commit

Permalink
Raspberry script & minor fixes (#37)
Browse files Browse the repository at this point in the history
* Github Actions badge
* python script to update raspberry
* fix lock not released on unknown error
  • Loading branch information
rodrigondec authored Jan 6, 2020
1 parent 81704d3 commit 87f193d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JackBot

[![CircleCI](https://img.shields.io/circleci/build/github/dcr-guys/JackBot)](https://circleci.com/gh/dcr-guys/JackBot)
[![Actions Status](https://github.com/dcr-guys/JackBot/workflows/Python%20application%20tests/badge.svg)](https://github.com/dcr-guys/JackBot/actions)
[![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)

JackBot is a Ticket Splitting Sessions watcher/notifier teleram bot
JackBot is a Ticket Splitting Sessions watcher/notifier telegram bot
2 changes: 1 addition & 1 deletion db/ticket.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ def get_last(cls):
last_ticket_price = cls._fetch_new_ticket_price()
finally:
last_ticket_price.save()
cls.lock.release()

cls.lock.release()
return last_ticket_price
5 changes: 5 additions & 0 deletions sws/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ def on_message(ws: WebSocketApp, data):
except DuplicatedUpdateMessageError as e:
logger.info(f"Supress {e} for creating {UpdateMessage} "
f"from {data} on {sws}")
except Exception as e:
logger.error(e)
finally:
if sws.lock.locked():
sws.lock.release()

@staticmethod
def on_error(ws, error: Exception):
Expand Down
9 changes: 6 additions & 3 deletions tests/db/test_update_message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import TestCase, mock

import pytest
import pendulum

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

def test_get_last_by_subject(self):
UpdateMessage(self.subject, [Session('test',
[Amount(1000000000)])]).save()
UpdateMessage(self.subject,
[Session('test', [Amount(1000000000)])],
pendulum.yesterday()).save()
other = UpdateMessage(self.subject,
[Session('test', [Amount(1100000000)])]).save()
[Session('test', [Amount(1100000000)])],
pendulum.today()).save()

last = UpdateMessage.get_last_by_subject(self.subject)
self.assertEqual(other, last)
Expand Down
34 changes: 34 additions & 0 deletions update_raspberry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import requests
import json
import tarfile
import subprocess

releases_url = "https://api.github.com/repos/dcr-guys/JackBot/releases"
releases_response = requests.get(releases_url)
releases_response.data = json.loads(releases_response.content)

latest = releases_response.data[0]
latest_tarball = requests.get(latest.get('tarball_url'))
latest_name = latest.get('name')

base_dir = f"./{latest_name}/"
tarfile_name = f"{base_dir}{latest_name}.tar.gz"

subprocess.run(["mkdir", base_dir])

with open(tarfile_name, 'wb') as file:
file.write(latest_tarball.content)

with tarfile.open(tarfile_name) as tar:
subfolder_name = tar.firstmember.name
tar.extractall(base_dir)

source_dir = f"{base_dir}/{subfolder_name}/"
dest_dir = "./"
subprocess.run(['rsync', '-av', source_dir, dest_dir])

subprocess.run(['rm', '-rf', base_dir])

subprocess.run(['make', 'docker.arm.down'])
subprocess.run(['make', 'docker.arm.build'])
subprocess.run(['make', 'docker.arm.up'])

0 comments on commit 87f193d

Please sign in to comment.