Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Commit

Permalink
Release V0.7.0
Browse files Browse the repository at this point in the history
0.7.0 / 2017-06-22
==================

  * Using VPS & Telegram bot
  * Update requests from 2.17.3 to 2.18.1 (#96)
  * Home page renders with or without releases
  * Scheduled daily dependency update on tuesday (#95)
  • Loading branch information
OGKevin committed Jun 22, 2017
2 parents b642d6f + 139375e commit 27ab255
Show file tree
Hide file tree
Showing 41 changed files with 611 additions and 90 deletions.
10 changes: 0 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,6 @@ before_script:
- ./manage.py collectstatic --noinput -v 0
script:
- coverage run ./manage.py test
deploy:
provider: heroku
api_key:
secure: rk8KBnZll+g7ZGUlMUx8utKt2QfEUL5MTFUkzMIwQpFFFSH9XU4mw/22g2hK4WSGsAByfGmEKuHCIk6X/jcEskJ49EuZLe+DNWYf2F9eRqe1WB5CQzlKTIskuO5gSv3XT2vrajdv5xUmotUMZVpw86xILd6Bb3Ob4a2YyD8JCzmhUPwspnrATGsOXxPKTG5h5EgKHWY4KWpS9frQonzuqN+lXf/E6y1ArViS6l0srMxuU0l60yG/DlajyCNv30a2sRWvTaYB9SEKjwuvauHlOve1rTYae/H0MKFvkOpRWqnNEiP/hP6qPLzQbEVQdT8xu+IdiE06Rn5Hm9Mr/m+o35dcsTiqy7HEGIltMYH+MuAepu3jEj59EX+AzoTYB/U3KQ5uTtWIJ6R17Lr8hF5fdkY8dACsV7BhnMwftb9uiBzb821yjViEA2OnQDFWFwKE4nyQeis51KRnUSaDtx8cNa4vBglP0L0v2mPzRbzqIwj8JarS2wRd1/KbetCLzxxex/kVFBlkfHjz8nXrjDyfYDza32aM70onQxGISpOMUXrVEFXHh0FF1KSZMhDZwFwueBrm+RU6/VWQ7uzxudEBXDanTcc8M5inDcrvIM0myCfn64AKDBE3HNVjAN+VGZZEqfsA8bZQ+cinrsDvzZaYkCF9do2Von9i0bjJENr/6Z0=
run:
- ./manage.py migrate
- restart
app: combunqweb
on:
tags: true
after_success:
- coveralls
notifications:
Expand Down
48 changes: 15 additions & 33 deletions BunqWebApp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,42 +44,23 @@
Exception('Please create a %s file with random characters \
to generate your secret key!' % SECRET_FILE)


# SECURITY WARNING: don't run with debug turned on in production!
if 'HEROKU' in os.environ: # pragma: no cover
DEBUG = False
SECURE_SSL_REDIRECT = True
SESSION_COOKIE_SECURE = True

RAVEN_CONFIG = {
'dsn': os.environ['DSN'],
}

DESABLE_LOGGERS = True

API_URI = os.environ['API_URI']
ALLOWED_HOSTS = ['.beta-combunqweb.herokuapp.com',
'.combunqweb.herokuapp.com', '.bunqweb.com']
USE_PROXY = True
PROXY_URI = os.environ['PROXY_URI']

if API_URI == 'True':
API_URI = True
else:
API_URI = False

else:
DEBUG = True
SECURE_SSL_REDIRECT = False
SESSION_COOKIE_SECURE = False
DESABLE_LOGGERS = False
API_URI = True
ALLOWED_HOSTS = ['*']
USE_PROXY = False
DEBUG = True
SECURE_SSL_REDIRECT = False
SESSION_COOKIE_SECURE = False
DESABLE_LOGGERS = False
SANDBOX = True
ALLOWED_HOSTS = ['*']
USE_PROXY = False
PROXY_URI = 'url'
TELEGRAM_TOKEN = None

SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
SESSION_EXPIRE_AT_BROWSER_CLOSE = True

RAVEN_CONFIG = {
'dsn': None,
}

# Application definition

INSTALLED_APPS = [
Expand All @@ -95,7 +76,8 @@
'simple_history',
'BunqAPI',
'raven.contrib.django.raven_compat',
'filecreator'
'filecreator',
'bunq_bot'
]

MIDDLEWARE = [
Expand Down
3 changes: 3 additions & 0 deletions BunqWebApp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from BunqWebApp import views
from filecreator.views import APIView as filecreator
from filecreator.views import FileDownloaderView as file_downlaoder
from bunq_bot.views import WebHook

# from django.contrib.auth import views as auth_views

'''
Expand Down Expand Up @@ -54,6 +56,7 @@
filecreator.as_view(), name='API'),
url(r'^filecreator/download$', file_downlaoder.as_view(),
name='filecreator'),
url(r'bot/%s$' % settings.TELEGRAM_TOKEN, WebHook.as_view(), name='bot'),
url(r'^captcha/', include('captcha.urls')),
# url(r'^.*$', views.RedirectView.as_view(), name='home'),
# NOTE: this redirect is not working properly
Expand Down
17 changes: 11 additions & 6 deletions BunqWebApp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import arrow
import markdown2
import datetime
import logging
# from django.http import HttpResponse
from django.contrib import messages
from BunqAPI.installation import Installation
Expand Down Expand Up @@ -43,12 +44,16 @@ def get_releases(self):
'https://api.github.com/repos/OGKevin/combunqwebapp/releases') \
.json()

data = res[:7]
for x in data:
x['created_at'] = arrow.get(x['created_at']).format('Do MMM')
x['body'] = markdown2.markdown(x['body'])

return data
try:
data = res[:7]
except TypeError as e:
logging.error(e)
return None
else:
for x in data:
x['created_at'] = arrow.get(x['created_at']).format('Do MMM')
x['body'] = markdown2.markdown(x['body'])
return data


class RegisterView(View):
Expand Down
7 changes: 7 additions & 0 deletions Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bunqweb.com {
proxy / localhost:8000
}

www.bunqweb.com {
proxy / localhost:8000
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.2 on 2017-06-13 13:55
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Manager', '0011_historicalcatagories'),
]

operations = [
migrations.AddField(
model_name='historicalcatagories',
name='history_change_reason',
field=models.CharField(max_length=100, null=True),
),
]
1 change: 0 additions & 1 deletion Procfile

This file was deleted.

2 changes: 1 addition & 1 deletion apiwrapper/clients/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ApiClient:
__variables = ['installation_id', 'installation_token', 'api_key',
'server_token', 'server_pubkey', 'session_token']

def __init__(self, privkey, use_sandbox=settings.API_URI, **kwargs):
def __init__(self, privkey, use_sandbox=settings.SANDBOX, **kwargs):
self.privkey = privkey
self._uri = self._uri_sandbox if use_sandbox else self._uri_production
self._handle_kwargs(kwargs)
Expand Down
30 changes: 0 additions & 30 deletions app.json

This file was deleted.

Empty file added bunq_bot/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions bunq_bot/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions bunq_bot/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BunqBotConfig(AppConfig):
name = 'bunq_bot'
13 changes: 13 additions & 0 deletions bunq_bot/automatic_messages/updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from bunq_bot.automatic_messages.updates_.news_updates import NewsUpdates
from bunq_bot.automatic_messages.updates_.together_updates import \
TogetherUpdates


class Updates():
def __init__(self, bot):
self.bot = bot

def send_updates(self):
NewsUpdates(self._bot).send_updates()
TogetherUpdates(self._bot).send_updates()
# self.send_updates()
59 changes: 59 additions & 0 deletions bunq_bot/automatic_messages/updates_/news_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import feedparser
import telegram
from trender import TRender
from html.parser import HTMLParser
from bunq_bot.models import BunqNews, ChatInfo


class NewsUpdates():

_url = 'https://www.bunq.com/en/news/feed.rss'
_feed = feedparser.parse(_url)

def __init__(self, bot):
self._bot = bot

def send_updates(self):
titles = list(BunqNews.objects.all().values_list('title',
flat=True))
for item in self._feed['items']:
if not item['title'] in titles:
self._send_upadte(item)
self._save_in_database(item)

def _save_in_database(self, item):
c = BunqNews(title=item['title'], author=item['author'])
c.save()

def _send_upadte(self, item):
chat_ids = list(ChatInfo.objects.all().values_list('chat_id',
flat=True))

for chat_id in chat_ids:
self._bot.send_message(
chat_id=chat_id,
text=self._text(item),
parse_mode=telegram.ParseMode.MARKDOWN
)

def _text(self, item):
s = MLStripper()
s.feed(item['summary'])
item['summary'] = s.get_data()

with open('bunq_bot/responses/automatic_messages/news_feed.md',
'r') as f:
return TRender(f.read()).render({'item': item})


class MLStripper(HTMLParser):
def __init__(self):
super().__init__()
self.reset()
self.fed = []

def handle_data(self, d):
self.fed.append(d)

def get_data(self):
return ''.join(self.fed)
64 changes: 64 additions & 0 deletions bunq_bot/automatic_messages/updates_/together_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import feedparser
import telegram
from trender import TRender
from html.parser import HTMLParser
from bunq_bot.models import BunqTogether, ChatInfo


class TogetherUpdates():

_url = 'https://together.bunq.com/rss'
_feed = feedparser.parse(_url)

def __init__(self, bot):
self._bot = bot

def send_updates(self):
titles = list(BunqTogether.objects.all().values_list('title',
flat=True))
for item in self._feed['items']:
if not item['title'] in titles:
try:
self._send_upadte(item)
except telegram.error.BadRequest:
self._send_upadte(item, False)
finally:
self._save_in_database(item['title'])

def _save_in_database(self, title):
c = BunqTogether(title=title)
c.save()

def _send_upadte(self, item, summary=True):
chat_ids = list(ChatInfo.objects.all().values_list('chat_id',
flat=True))

for chat_id in chat_ids:
self._bot.send_message(
chat_id=chat_id,
text=self._text(item, summary),
parse_mode=telegram.ParseMode.MARKDOWN
)

def _text(self, item, summary=True):
s = MLStripper()
s.feed(item['summary'])
item['summary'] = s.get_data()

with open('bunq_bot/responses/automatic_messages/together_feed.md',
'r') as f:
return TRender(f.read()).render({'item': item,
'summary': summary})


class MLStripper(HTMLParser):
def __init__(self):
super().__init__()
self.reset()
self.fed = []

def handle_data(self, d):
self.fed.append(d)

def get_data(self):
return ''.join(self.fed)
3 changes: 3 additions & 0 deletions bunq_bot/commands/commandos/help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def help():
with open('bunq_bot/responses/commands/help.md', 'r') as f:
return f.read()
37 changes: 37 additions & 0 deletions bunq_bot/commands/commandos/news.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import feedparser
from trender import TRender
# from pprint import pprint
from html.parser import HTMLParser


def news():
url = 'https://www.bunq.com/en/news/feed.rss'
feed = feedparser.parse(url)

data = []
for item in feed['items']:
s = MLStripper()
s.feed(item['summary'])
obj = {
'title': item['title'],
'date': item['published'],
'summary': s.get_data(),
'link': item['link'],
'author': item['author']
}
data.append(obj)
with open('bunq_bot/responses/commands/news.md', 'r') as f:
return TRender(f.read()).render({'data': data[:5]})


class MLStripper(HTMLParser):
def __init__(self):
super().__init__()
self.reset()
self.fed = []

def handle_data(self, d):
self.fed.append(d)

def get_data(self):
return ''.join(self.fed)
3 changes: 3 additions & 0 deletions bunq_bot/commands/commandos/start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def start():
with open('bunq_bot/responses/commands/start.md') as f:
return f.read()
Loading

0 comments on commit 27ab255

Please sign in to comment.