Beispiel #1
0
 def __init__(self):
     """
     Constructor
     """
     DatabaseClient.__init__(self)
     self.conn = None
     self.lock = threading.Lock()
Beispiel #2
0
def main():
    start = time.time()
    print("Starttime: %s" % str(datetime.datetime.now()))
    dbClient = DatabaseClient()
    # for some reason we have to do this once (maybe to establish connection but dunno)
    dbClient.getLatestTweetId('audi_etron', 1, 1)
    # maybe wait for connection?
    time.sleep(1)
    # 40 tweets every 3 seconds = 12.000 tweets per 15 minutes
    populateTweetsInDatabase(
        'audi_etron', 'audi etron OR audi e-tron OR audi e tron', 30, 30, dbClient)
    populateTweetsInDatabase('audi', 'audi', 30, 30, dbClient)
    populateTweetsInDatabase(
        'google_stadia', 'google stadia OR stadia', 30, 30, dbClient)
    populateTweetsInDatabase('google', 'google', 30, 30, dbClient)
    populateTweetsInDatabase(
        'volkswagen', 'vw OR volkswagen', 30, 30, dbClient)
    populateTweetsInDatabase(
        'volkswagen_id3', 'vw id.3 OR volkswagen id.3 OR vw id3 OR volkswagen id3 OR volkswagen id 3', 30, 30, dbClient)
    populateTweetsInDatabase(
        'mercedes', 'mercedes OR mercedes-benz', 30, 30, dbClient)
    populateTweetsInDatabase(
        'mercedes_eqc', 'mercedes eqc OR mercedes-benz eqc OR benz eqc', 30, 30, dbClient)

    print('Script took ' + str(time.time() - start) + ' seconds to execute.')
    print("Endtime: %s" % str(datetime.datetime.now()))
Beispiel #3
0
 def __init__(self):
     """
     Constructor
     """
     DatabaseClient.__init__(self)
     self.context = zmq.Context()
     self.conn = self.context.socket(zmq.PUB)
     self.lock = threading.Lock()
Beispiel #4
0
 def __init__(self, logger):
     """
     Constructor
     """
     DatabaseClient.__init__(self)
     self.conn = None
     self.cursor = None
     self.lock = threading.Lock()
     self.logger = logger
    def __init__(self, dir=os.getcwd()):
        """
        Constructor
        """
        DatabaseClient.__init__(self)
        self.lock = threading.Lock()
        self.file_mapping = dict()

        if dir is None or dir == '':
            raise Exception("FileClient does not accept empty directory.")

        self.file_directory = dir
Beispiel #6
0
    def __init__(self, app, client="", token=""):
        super(GUI, self).__init__()
        self.messages_to_play = []
        self.database_client = DatabaseClient()
        self.local_socket_client = LocalClient(self.database_client)
        self.socket_client = None
        if token:
            if client == 'Streamlabs':
                self.socket_client = StreamlabsClient(self.database_client,
                                                      token)
            if client == 'StreamElements':
                self.socket_client = StreamElementsClient(
                    self.database_client, token)
        self.app = app
        self.setupUi(self)
        self.setWindowTitle("bart3s tts")
        self.setFixedWidth(600)
        self.setFixedHeight(600)

        self.logs = []
        self.logs2 = []
        self.max_log_lines = 100
        self.max_log2_lines = 100
        self.connected = False
        self.current_audio_length = 0
        self.files = []

        self.ClientSkipAudio.clicked.connect(self.skip_wav)
        self.ClientStopBtn.setDisabled(True)
        self.ClientSkipAudio.setDisabled(True)
        self.ClientRemoveAudio.clicked.connect(self.delete_first_message)
        self.ClientRemoveAudio.setEnabled(True)
        self.log_window.ensureCursorVisible()
        self.log_window2.ensureCursorVisible()
        self.volumeSlider.valueChanged.connect(self.change_volume)

        pygame.mixer.quit()
        pygame.mixer.init(frequency=22050, size=-16, channels=1)
        self.channel = pygame.mixer.Channel(0)

        self.generated_audio_path = "generated_audio/"
        if not os.path.exists(self.generated_audio_path):
            os.makedirs(self.generated_audio_path)

        self.ClientStartBtn.clicked.connect(self.start)
        self.ClientStopBtn.clicked.connect(self.stop)
        self.threadpool = QThreadPool()
        self.threadpool.setMaxThreadCount(3)
        print("Multithreading with maximum {} threads".format(
            self.threadpool.maxThreadCount()))
        self.signals = GUISignals()
        self.tts_engine = TextToSpeechEngine(self.generated_audio_path)
class Application:
    def __init__(self):
        self.keywords = ["numpy", "scikit", "tensorflow", "pytorch", "matlab"]
        self.github_fetcher = GithubFetcher(self.keywords)
        self.paper_fetcher = PaperFetcher()
        self.db = DatabaseClient()

    def get_paper_stats(self):
        # Returns the (paper, conference, libraries) tuple of the most recently
        # processed data. Not guranteed to be fresh.
        rows = self.db.get_all_papers_stats()
        formatted_result = []
        for row in rows:
            column_names = ['paper_title', 'conference_name'] + self.keywords
            zipped = zip(column_names, row)
            formatted_result.append(zipped)
        return formatted_result

    def get_conference_stats(self):
        # Returns the (conference, library_count) tuple for each conference.
        # Not guranteed to be fresh.
        rows = self.db.get_all_conference_stats()
        formatted_result = []
        for row in rows:
            column_names = ['conference_name'] + self.keywords
            zipped = zip(column_names, row)
            formatted_result.append(zipped)
        return formatted_result

    def start(self, response):
        if response == "0":
            # Run the offline pipeline.
            self.paper_fetcher.start()
            self.github_fetcher.start()
            self.aggregator.start()
        elif response == "1":
            results = self.get_paper_stats()
            for result in results:
                print "================================="
                print result
        elif response == "2":
            results = self.get_conference_stats()
            for result in results:
                print "================================="
                print result
        else:
            print "Not a valid response"
 def __init__(self, 
              api_socket, 
              db_client=DatabaseClient()):
     """
     Constructor
     :param exchange_name: Exchange name
     :param exchange_api: Exchange API
     :param db_client: Database client
     """
     self.db_client = db_client
     self.api_socket = api_socket
Beispiel #9
0
def get_cloud_data(keyword):
    for i in range(0, 5):
        try:
            dbClient = DatabaseClient()

            tweets = list(dbClient.getAllDocuments(keyword))
            print(
                "Currently there are %s tweets stored in the database collection '%s'."
                % (str(len(tweets)), keyword))

            max_id = max(list(map(lambda tweet: int(tweet['id_str']), tweets)))
            print("Id of latest fetched tweet is %s." % str(max_id))

            with open(keyword + '_data.json', 'w+') as f:
                # f.write(json.dumps(tweets, default=json_util.default, indent=4))
                json.dump(tweets, f, default=json_util.default, indent=4)
            return tweets
        except:
            print("A Database Error... Wait 10sec an try again")
            time.sleep(10)
def main():

    main = 'volkswagen'
    extension = 'volkswagen_id3'

    dbClient = DatabaseClient()
    termFrequencyMain = calculateTermFrequency(dbClient, main)
    termFrequencyMain.pop(main, None)
    fDist = FreqDist(termFrequencyMain)
    fDist.plot(35)

    termFrequencyExtension = calculateTermFrequency(dbClient, extension)
    # pretty output
    termFrequencyExtension.pop(main, None)
    termFrequencyExtension.pop('id3', None)
    fDist = FreqDist(termFrequencyExtension)
    fDist.plot(35)

    meanDifference = calculateMeanFractionalDifference(termFrequencyMain,
                                                       termFrequencyExtension)
    print('Mean difference in frequency as measure for product fit: ' +
          str(meanDifference))
from database_client import DatabaseClient
from datetime import datetime, timedelta
import matplotlib.dates
import matplotlib.pyplot as plt
import json

dbClient = DatabaseClient()


def calculateVisibilityForToday():
    # get fraction for the live timeframe (3 days currently)
    threeDaysAgo = datetime.now() - timedelta(days=3)

    tweetsMainLast3daysCount = len(list(filter(lambda tweet: datetime.strptime(
        tweet['created_at'], '%a %b %d %H:%M:%S +0000 %Y') >= threeDaysAgo, dbClient.getAllDocuments("mercedes"))))

    tweetsExtensionLast3daysCount = len(list(filter(lambda tweet: datetime.strptime(
        tweet['created_at'], '%a %b %d %H:%M:%S +0000 %Y') >= threeDaysAgo, dbClient.getAllDocuments("mercedes_eqc"))))

    fraction = tweetsExtensionLast3daysCount / tweetsMainLast3daysCount
    print("visibility of extension is: " + str(fraction))


def calculateGraphOverTime(main, extension, fit):
    # get all tweets for main brand and extension
    twoWeeksAgo = datetime.now() - timedelta(days=14)

    # only take tweets from last 14 days
    tweetsMainLastTwoWeeks = list(filter(lambda tweet: datetime.strptime(
        tweet['created_at'], '%a %b %d %H:%M:%S +0000 %Y') > twoWeeksAgo, dbClient.getAllDocuments(main)))
def parseAthlete(url):
    try:
        client = DatabaseClient()
        client.connect("localhost", 27017)
        page = urllib2.urlopen(url)
        soup = BeautifulSoup(page.read(), "lxml")
        div = soup.findAll("div", {"class": "L8"})
        athlete_id = url.replace(
            "http://www.athletic.net/TrackAndField/Athlete.aspx?AID=", "")
        name = soup.find("h2", {"class": "mTop10"})
        school = soup.find("h1", {"class": "mTop10"})
        name = name.contents[1]
        school = school.a.contents[0]
        athlete = Athlete(athlete_id, name)
        for i in div:
            season = i.h4.span.contents[0]
            season_obj = Season(str(school), season)
            print(season)
            panel = i.findAll("div", {"class": "panel-body"})
            for j in panel:
                h5 = j.findAll('h5')
                table = j.findAll("tbody")
                for y in range(0, len(table)):
                    event = h5[y].contents[0]
                    print(event)
                    db_item = DBItem(str(event))
                    tr = table[y].findAll("tr")
                    for l in tr:
                        td = l.findAll("td")
                        for x in range(len(td)):
                            if td[x].find('a') != None:
                                string = td[x].find('a').contents[0]
                                if "<i" not in str(string):
                                    print(string)
                                    if x == 1:
                                        db_item.add_time(str(string))
                                    elif x == 2:
                                        db_item.add_day(str(string))
                                    elif x == 3:
                                        db_item.add_meet(str(string))
                            elif td[x].find('i') != None:
                                string = td[x].find('i').contents[0]

                                print(string)
                                if x == 1:
                                    db_item.add_time(str(string))
                                elif x == 2:
                                    db_item.add_day(str(string))
                                elif x == 3:
                                    db_item.add_meet(str(string))
                            else:
                                string = td[x].contents[0]
                                print(string)
                                if x == 1:
                                    db_item.add_time(str(string))
                                elif x == 2:
                                    db_item.add_day(str(string))
                                elif x == 3:
                                    db_item.add_meet(str(string))
                    season_obj.add_event(db_item)
            athlete.add_season(season_obj)

        strn = json.dumps(athlete, default=jdefault)

        client.insert(json.loads(strn))
    except:
        print("error")
 def __init__(self, db=DatabaseClient()):
     self.db = db
Beispiel #14
0
from database_client import DatabaseClient

db_client = DatabaseClient()
msgs = db_client.get_all_generated_messages()
for i, m in enumerate(msgs):
    print(m.get('text'))
Beispiel #15
0
from flask import jsonify
from pprint import pprint
from random import choice
import json
import random
from database_client import DatabaseClient, get_current_epoch_datetime
from bson.objectid import ObjectId
import pymongo

# These remain constant throughout every game
TILE_UNKNOWN = 0
TILE_HIT = 1
TILE_MISS = 2

app = Flask(__name__)
db = DatabaseClient()


def get_auth_error_json():
    """Return the authention error (JSON format)"""
    return jsonify({
        "status": "error",
        "error-id": 5,
        "description": "Invalid auth key."
    })


def get_other_player(current_player, player_list):
    """Return the name of the opponent of the given player, given the current player and the list of both players"""
    return player_list[1] if current_player == player_list[0] else player_list[
        0]
Beispiel #16
0
import base64

from fastapi import FastAPI, HTTPException, Request, Response
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import Response, FileResponse, StreamingResponse
import pandas as pd
import cv2

from database_client import DatabaseClient
from models.cluster_labels import ClusterLabels

# Create web app and database connection
app = FastAPI()
db_client = DatabaseClient(
    user="******",
    database="db",
    host=os.environ.get("DB_HOST", "localhost"),
    password=os.environ["DB_PASSWORD"],
)
signal.signal(signal.SIGINT, db_client.close)
signal.signal(signal.SIGTERM, db_client.close)

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# Username to use if no name was given by http basic auth
DEFAULT_USER = "******"
Beispiel #17
0
#!/usr/bin/env python
# coding=UTF-8

import time
import os
from poloniex import Poloniex
from database_client import DatabaseClient
from bottle import route, run, template
from trade_bot import TradeBot

poloniex = Poloniex()
bot = TradeBot()
db = DatabaseClient(bot)


@route('/clear/<currency>')
def clear(currency):
    return bot.clear(currency)


@route('/force_buy/<currency>')
def update(currency):
    return bot.force(currency, 'Buy')


@route('/force_sell/<currency>')
def update(currency):
    return bot.force(currency, 'Sell')


@route('/update.json')
 def __init__(self):
     self.keywords = ["numpy", "scikit", "tensorflow", "pytorch", "matlab"]
     self.github_fetcher = GithubFetcher(self.keywords)
     self.paper_fetcher = PaperFetcher()
     self.db = DatabaseClient()
Beispiel #19
0
class GUI(QMainWindow, Ui_MainWindow):
    def __init__(self, app, client="", token=""):
        super(GUI, self).__init__()
        self.messages_to_play = []
        self.database_client = DatabaseClient()
        self.local_socket_client = LocalClient(self.database_client)
        self.socket_client = None
        if token:
            if client == 'Streamlabs':
                self.socket_client = StreamlabsClient(self.database_client,
                                                      token)
            if client == 'StreamElements':
                self.socket_client = StreamElementsClient(
                    self.database_client, token)
        self.app = app
        self.setupUi(self)
        self.setWindowTitle("bart3s tts")
        self.setFixedWidth(600)
        self.setFixedHeight(600)

        self.logs = []
        self.logs2 = []
        self.max_log_lines = 100
        self.max_log2_lines = 100
        self.connected = False
        self.current_audio_length = 0
        self.files = []

        self.ClientSkipAudio.clicked.connect(self.skip_wav)
        self.ClientStopBtn.setDisabled(True)
        self.ClientSkipAudio.setDisabled(True)
        self.ClientRemoveAudio.clicked.connect(self.delete_first_message)
        self.ClientRemoveAudio.setEnabled(True)
        self.log_window.ensureCursorVisible()
        self.log_window2.ensureCursorVisible()
        self.volumeSlider.valueChanged.connect(self.change_volume)

        pygame.mixer.quit()
        pygame.mixer.init(frequency=22050, size=-16, channels=1)
        self.channel = pygame.mixer.Channel(0)

        self.generated_audio_path = "generated_audio/"
        if not os.path.exists(self.generated_audio_path):
            os.makedirs(self.generated_audio_path)

        self.ClientStartBtn.clicked.connect(self.start)
        self.ClientStopBtn.clicked.connect(self.stop)
        self.threadpool = QThreadPool()
        self.threadpool.setMaxThreadCount(3)
        print("Multithreading with maximum {} threads".format(
            self.threadpool.maxThreadCount()))
        self.signals = GUISignals()
        self.tts_engine = TextToSpeechEngine(self.generated_audio_path)

    @pyqtSlot(str)
    def draw_text(self, text):
        obj = text[0:4]
        msg = text[5:]
        if obj == "Log1":
            if len(self.logs2) > self.max_log2_lines:
                self.logs2.pop(0)
            self.logs2.append(msg)
            log_text = "\n".join(self.logs2)
            self.log_window.setPlainText(log_text)
            self.log_window.verticalScrollBar().setValue(
                self.log_window.verticalScrollBar().maximum())
        if obj == "Log2":
            self.log_window2.setPlainText(msg)
        if obj == "Sta1":
            self.statusbar.setText(msg)

    @pyqtSlot(int)
    def print_elapsed(self, val):
        pass

    def thread_complete(self):
        pass

    def print_output(self, s):
        pass

    def closeEvent(self, event):
        global _running
        if _running:
            event.ignore()
        else:
            self.local_socket_client.disconnect()
            if self.socket_client:
                self.socket_client.disconnect()
            event.accept()

    def start(self):
        global _running
        _mutex1.lock()
        _running = True
        _mutex1.unlock()
        self.connected = True
        worker = Worker(self.execute_this_fn, self.channel)
        worker.signals.result.connect(self.print_output)
        worker.signals.finished.connect(self.thread_complete)
        worker.signals.textready.connect(self.draw_text)

        self.threadpool.start(worker)

        worker2 = Worker(self.play_audio_fn, self.channel)
        worker2.signals.result.connect(self.print_output)
        worker2.signals.finished.connect(self.thread_complete)
        worker2.signals.textready.connect(self.draw_text)

        self.threadpool.start(worker2)

    def stop(self):
        global _running
        _mutex1.lock()
        _running = False
        _mutex1.unlock()
        self.skip_wav()

    def execute_this_fn(self, channel, progress_callback, elapsed_callback,
                        text_ready):
        self.ClientStartBtn.setDisabled(True)
        self.ClientStopBtn.setEnabled(True)
        self.ClientSkipAudio.setEnabled(True)
        text_ready.emit("Log1:TTS engine started!")
        while True:
            _mutex1.lock()
            if _running == False:
                _mutex1.unlock()
                break
            else:
                _mutex1.unlock()
            while self.database_client.is_messages_collection_not_empty(
            ) and self.connected:
                message = self.database_client.get_first_message_in_queue()
                text_ready.emit("Log2:{} donated!\nID: {}\n{}".format(
                    message.name, message.messageId, message.text))
                try:
                    start_time = time.time()
                    generated_audio = self.tts_engine.generate_audio(message)
                    if generated_audio:
                        text_ready.emit(
                            "Sta1:Generating message: {} took: {} seconds.".
                            format(message.messageId,
                                   str(round((time.time() - start_time), 2))))
                        generated_audio.messageId = message.messageId
                        self.messages_to_play.append(generated_audio)
                        self.database_client.add_generated_message(message)
                    else:
                        text_ready.emit(
                            "Sta1:Message: {}\nwas automatically skipped!".
                            format(message.messageId))
                    self.database_client.delete_message(message.messageId)
                except:
                    self.connected = False
                    text_ready.emit("Log1:\nCan't connect to TTS server!")
                    self.stop()
                text_ready.emit("Log2:")
            time.sleep(0.5)
        self.ClientStartBtn.setEnabled(True)
        self.ClientStopBtn.setDisabled(True)
        self.ClientSkipAudio.setDisabled(True)
        text_ready.emit("Log1:TTS engine stopped!")
        return "Return value of execute_this_fn"

    def play_audio_fn(self, channel, progress_callback, elapsed_callback,
                      text_ready):
        while True:
            _mutex1.lock()
            if _running == False:
                _mutex1.unlock()
                break
            else:
                _mutex1.unlock()
            while self.messages_to_play:
                if not channel.get_busy() and self.current_audio_length == 0:
                    time.sleep(1)
                    generated_audio = self.messages_to_play.pop(0)
                    name = generated_audio.message.name
                    text = generated_audio.message.text
                    messageId = generated_audio.message.messageId
                    files = generated_audio.files
                    text_ready.emit(
                        "Log1:------------------------------------------------------------------------------------\n"
                    )
                    text_ready.emit("Log1:{} donated!".format(name))
                    text_ready.emit("Log1:ID: {}".format(messageId))
                    text_ready.emit("Log1:{}".format(text))
                    self.current_audio_length = generated_audio.length
                    self.files = files
                    while self.current_audio_length > 0:
                        if not channel.get_busy() and len(self.files) > 0:
                            self.playback_wav(self.files.pop(0))

            time.sleep(0.5)
        return "Return value of play_audio_fn"

    def playback_wav(self, file):
        voice = file.voice
        wav = file.text
        if voice == "satan:":
            pygame.mixer.quit()
            pygame.mixer.init(frequency=11000, size=-16, channels=1)
            self.channel = pygame.mixer.Channel(0)
        else:
            pygame.mixer.quit()
            pygame.mixer.init(frequency=22050, size=-16, channels=1)
            self.channel = pygame.mixer.Channel(0)
        sound = pygame.mixer.Sound(wav)
        if voice == "keanu:":
            self.channel.set_volume(self.volumeSlider.value() / 100)
        else:
            self.channel.set_volume((self.volumeSlider.value() / 100) * 0.9)
        self.channel.queue(sound)
        self.current_audio_length -= 1
        self.ClientSkipAudio.setEnabled(True)

    def skip_wav(self):
        if self.channel.get_busy():
            self.files = []
            self.channel.stop()
            self.channel = pygame.mixer.Channel(0)
            self.current_audio_length = 0

    def delete_first_message(self):
        if self.database_client.is_messages_collection_not_empty():
            message = self.database_client.get_first_message_in_queue()
            self.database_client.delete_message(message.messageId)

    def change_volume(self):
        value = self.volumeSlider.value()
 def __init__(self, keywords, db = DatabaseClient()):
   self.g = GithubSearchClient("a77d4b49fac3f43fa1d1df585ea62aa6fc17401c")
   self.keywords = keywords
   self.db = db