Esempio n. 1
0
from functools import wraps
from helpers.log import get_logger

logger = get_logger('exception')

#......... Simple Decorator for Generic Exception Handler .........#


def exception_handler(return_if_exception=None):
    ''' decorator for generic exeption handling

		Params:
		* return_if_exception : it will be returned if any
								exeption occurs o/w normal return
		e.g.
		----------------------------------------------------------
		# return empty list if any exception occur o/w normal flow

		@exception_handler([])
		def my_func(a, b):
			...
			...
		----------------------------------------------------------
		# return None (default) if any exception occur o/w normal flow

		@exception_handler()
		def my_func(a, b):
			...
			...
		---------------------------------------------------------
Esempio n. 2
0
from selenium.common.exceptions import TimeoutException, StaleElementReferenceException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from helpers.config import read_config
from helpers.connections import get_rethink_connection
from helpers.context_filter import ContextFilter
from helpers.icalendar import get_today
from helpers.log import get_logger

logger = get_logger()

STOCK_PICKS = 'barrons_picks'


def parse_arguments():
    ''' parse arguments '''

    # parse arguments
    parser = argparse.ArgumentParser(description='Barrons Picks')
    parser.add_argument('--config', action='store', dest='config',\
     required=True, help='config')
    parser.add_argument('--date', action='store', dest='date',\
     required=False, help='process_date')
    parser.add_argument('--year', action='store', dest='year',\
     required=False, help='process_year')
Esempio n. 3
0
weather_icons = {
    'clear-day': ':sunny:',
    'clear-night': ':night_with_stars:',
    'fog': ':foggy:',
    'hail': ':cloud_snow:',
    'sleet': ':cloud_snow:',
    'snow': ':cloud_snow:',
    'partly-cloudy-day': ':partly_sunny:',
    'cloudy': ':cloud:',
    'partly-cloudy-night': ':cloud:',
    'tornado': ':cloud_tornado:',
    'wind': ':wind_blowing_face:'
}

logger = log.get_logger(__name__)


class Utility(commands.Cog):
    def __init__(self, client):
        self.client = client

    @commands.command()
    async def weather(self, ctx, *address):
        """Get weather of given location.

        Usage:
            >weather
            >weather <location>
            >weather save <location>
        """
Esempio n. 4
0
import logging.handlers
import os
import rethinkdb as r
import sys

sys.path.insert(0,
                os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from datetime import datetime, timedelta
from time import strptime
from utils import read_config
from utils.connections import get_rethink_connection

from helpers.log import get_logger

logger = get_logger("influencer-historic")

DB_NAME = "test"
TABLE_ARTICLE_INFO = "article_info"
TABLE_HISTORIC_ARTICLE_INFO = "historic_article_info"

# setting logger
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logger = logging.getLogger()
logger.setLevel(logging.INFO)


def parse_arguments():
    """ parse arguments """

    # parse arguments
import paho.mqtt.client as mqtt
import rethinkdb as r
import urlparse
from logging import getLogger
from helpers.log import get_logger

logger = get_logger("mqtt_client")

nabo_channels = [
        "/sample/v1/#",
        ]
r.connect("0.0.0.0", 32768).repl()
r_table = r.db("nabovarme").table("samples")

def on_connect(client, userdata, flags, rc):
    print "connected"
    [client.subscribe(channel) for channel in nabo_channels]

def on_message(client, userdata, msg):
    try:
        payload = urlparse.parse_qs(urlparse.urlsplit(msg.payload).path)
        payload = {key:value for key,value in ((key,dict(zip(["value", "unit"], values[0].split(" ")))) for key, values in payload.iteritems())}
        payload.pop("heap", None)
        doc = dict(zip(["meter_id", "unix_time"],[int(val) for val in msg.topic.split("/")[3:]]))
        doc['unix_time'] = r.epoch_time(doc["unix_time"])
        doc["payload"] = payload
        if payload:
           res = r_table.insert(doc).run()
           if not res["inserted"] == 1:
               msg = "not inserted! topic:{} payload:{}".format(msg.topic, msg.payload)
               raise ValueError(msg)
Esempio n. 6
0
import traceback
import discord
from discord.ext import commands
from helpers import log, utilityfunctions as util
from cogs.lastfm import LastFMError

logger = log.get_logger(__name__)
command_logger = log.get_logger("commands")


class Events(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_command_error(self, ctx, error):
        """The event triggered when an error is raised while invoking a command.

        ctx   : Context
        error : Exception
        """

        if hasattr(ctx.command, 'on_error'):
            return

        error = getattr(error, 'original', error)

        if isinstance(error, commands.CommandNotFound):
            return

        if isinstance(error, commands.MissingRequiredArgument):
Esempio n. 7
0
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By

from bs4 import BeautifulSoup

from urllib.parse import urlparse

import traceback

from time import strptime
from utils import read_config

from helpers.log import get_logger

logger = get_logger("influencer")

TABLE_STORY_INFO = "story_info"
TABLE_ARTICLE_INFO = "article_info"
TABLE_AUTHOR_INFO = "author_info"
DB_NAME = "test"

db_cache = {}

from helpers.connections import get_mongo_connection

import pymongo


def save_to_db(article, db, collection, config):
    mongo_connection = get_mongo_connection(config)
Esempio n. 8
0
from bs4 import BeautifulSoup

from datetime import datetime

from dateutil.parser import parse

from helpers.config import read_config
from helpers.connections import get_rethink_connection
from helpers.exception import exception_handler
from helpers.icalendar import get_today
from helpers.log import get_logger

from urllib.request import urlopen
from urllib.error import URLError

logger = get_logger()


def parse_arguments():
	''' parse arguments '''

	parser = argparse.ArgumentParser(description='Pre Market Hours Downloader')
	parser.add_argument('--config', action='store', dest='config', \
		required=True, help='config')
	result = parser.parse_args()
	return result

@exception_handler(return_if_exception=[])
def parse_pre_hours_movers(div_table):
	''' parse_pre_hours_movers '''
Esempio n. 9
0
from datetime import datetime

from helpers.config import read_config
from helpers.connections import get_rethink_connection
from helpers.exception import exception_handler
from helpers.icalendar import get_today
from helpers.log import get_logger

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException, StaleElementReferenceException

logger = get_logger()

ANALYST_FORECASTS = 'analyst_forecasts'


def parse_arguments():
    ''' parse arguments '''

    # parse arguments
    parser = argparse.ArgumentParser(description='Analyst Forecast')
    parser.add_argument('--config', action='store', dest='config',\
     required=True, help='config')
    parser.add_argument('--date', action='store', dest='date',\
     required=False, help='process_date')
    result = parser.parse_args()
    return result