Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Packages and cPrint method - pip upgrader also included
  • Loading branch information
Javinator9889 committed Jun 18, 2018
1 parent 79d85e3 commit e6fede7
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 4 deletions.
27 changes: 23 additions & 4 deletions App/application.py
@@ -1,8 +1,13 @@
from argparse import ArgumentParser, Namespace

from .out import cPrint, Colors
from .upgrader import PiPUpgrader


def main(arguments: Namespace):
from os import path
import pickle

token = arguments.token
youtube_api_key = arguments.youtube
creator_id = arguments.creator
Expand All @@ -12,18 +17,32 @@ def main(arguments: Namespace):
exit(0)
if not path.exists("app_data.dict"):
if not token:
ValueError("You must add token at least the first time you execute this app")
raise ValueError("You must add token at least the first time you execute this app")

This comment has been minimized.

Copy link
@Look-ATmeee
elif not youtube_api_key:
ValueError("You must include the YouTube API Key at least the first time you execute this app")
raise ValueError("You must include the YouTube API Key at least the first time you execute this app")
elif not creator_id:
ValueError("You must include the creator ID (Telegram) at least the first time you execute this app")
raise ValueError("You must include the creator ID (Telegram) at least the first time you execute this app")
else:
with open("app_data.dict", "wb") as app_data_file:
import pickle
app_data = {"TOKEN": token,
"YT_API": youtube_api_key,
"CREATOR_ID": creator_id}
pickle.dump(app_data, app_data_file, pickle.HIGHEST_PROTOCOL)
else:
cPrint("Initializing bot...", Colors.GREEN)
cPrint("Looking for packages updates...", Colors.GREEN)
upgrader = PiPUpgrader("requirements.txt")
upgrader.upgradePackages()
cPrint("Obtaining values...", Colors.GREEN)
with open("app_data.dict", "rb") as app_data_file:
app_data = pickle.load(app_data_file)
from telegram.ext import Updater
updater = Updater(token=app_data["TOKEN"], workers=50)
dispatcher = updater.dispatcher
import logging
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.DEBUG)
updater.start_polling(poll_interval=5, timeout=60)


if __name__ == '__main__':
Expand Down
27 changes: 27 additions & 0 deletions App/out/__init__.py
@@ -0,0 +1,27 @@
class Colors:
RED = "red"
BLUE = "blue"
GREEN = "green"
WARNING = "warning"
FAIL = "fail"
BOLD = "bold"
UNDERLINE = "underline"
RESET_ALL = "reset_all"


class OutputColors:
colors = {Colors.RED: '\033[95m',
Colors.BLUE: '\033[94m',
Colors.GREEN: '\033[92m',
Colors.WARNING: '\033[93m',
Colors.FAIL: '\033[91m',
Colors.BOLD: '\033[1m',
Colors.UNDERLINE: '\033[4m',
Colors.RESET_ALL: '\033[0m'}


def cPrint(text: str, color: Colors = None):
colors = OutputColors.colors
if color is None:
color = colors[Colors.RESET_ALL]
print(colors[color] + text + colors[Colors.RESET_ALL])
2 changes: 2 additions & 0 deletions App/requirements.txt
@@ -0,0 +1,2 @@
pip
python-telegram-bot
10 changes: 10 additions & 0 deletions App/upgrader/__init__.py
@@ -0,0 +1,10 @@
class PiPUpgrader:
def __init__(self, file: str):
self.__file = file

def upgradePackages(self):
import subprocess
with open(self.__file, 'r') as f:
requirements = f.read().splitlines()
for requirement in requirements:
subprocess.run(("pip install -U " + requirement).split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)

1 comment on commit e6fede7

@Look-ATmeee
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.