Example #1
0
 def __init__(self, name):
     super(App, self).__init__(name)
     nlp = spacy.load('./bandersnatch_nlu')
     self.evaluator = Evaluator(nlp)
     self.replier = Replier(nlp)
     self.BSN = 'https://playscenario.dscvit.com/api/bandersnatch/play'
     print('Worker started')
Example #2
0
def main(key):
    global LAST_UPDATE_ID

    logging.basicConfig(filename='log/screaming.log', level=logging.WARNING,
                        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

    bot = telegram.Bot(key)

    try:
        LAST_UPDATE_ID = bot.getUpdates()[-1].update_id
    except Exception:
        LAST_UPDATE_ID = None

    default, other = load('config.json')
    replier = Replier(bot, default, *other)

    while True:
        for update in bot.getUpdates(offset=LAST_UPDATE_ID, timeout=10):
            LAST_UPDATE_ID = replier.reply(update)
Example #3
0
 def update(self, user):
     conversation = self.conversation_dict.get(user.username)
     if conversation:
         self.update_conversation_dict(user.username)
         return conversation
     else:
         conversation = Conversation(user, Replier(user))
         new_conversation_dict = {user.username: conversation}
         self.conversation_dict.update(new_conversation_dict)
         return conversation
Example #4
0
class tweet_mama:
	def __init__(self):
		self.CONSUMER_KEY = '4qhVwgXY2ZZvbEN2qGTzdw'
		
		self.CONSUMER_SECRET = 'OdfyJE3NUpckodvGDw3fJmzivSz2xDdKd7ZDsNsf0Q'
		#self.ACCESS_KEY = '510800394-Zep39CczM0HKUGYKC5R5G2vlLzWyA2aJZxVx9Dx5'
		#self.ACCESS_SECRET = 'hHZdSFabzArRNQ0cQwrNGXcbCIdGNcUgGQ7qCD3c0'
		
		self.ACCESS_KEY = '510800394-Z7eeQiLIZOCccMbjyPElbSRyQb9SiezBax2C4tHq'
		self.ACCESS_SECRET = 'ioVceYgrfaPJ1sYCSXhdOqLef9przgmRCBhDg9Q'
		
		auth = tweepy.OAuthHandler(self.CONSUMER_KEY, self.CONSUMER_SECRET)
		auth.set_access_token(self.ACCESS_KEY, self.ACCESS_SECRET)
		self.replier = Replier()		
		
		self.api = tweepy.API(auth)
	
	def register(self):	
		auth = tweepy.OAuthHandler(self.CONSUMER_KEY, self.CONSUMER_SECRET)
		auth_url = auth.get_authorization_url()
		print 'Please authorize: ' + auth_url
		verifier = raw_input('PIN: ').strip()
		auth.get_access_token(verifier)
		print "ACCESS_KEY = '%s'" % auth.access_token.key
		print "ACCESS_SECRET = '%s'" % auth.access_token.secret


	def tweet(self,text):
		self.api.update_status(text)
	
	def mentions(self):
		m = self.api.mentions()
		
		#texts = [ n.text for n in m ]
		texts = [ n.user.screen_name for n in m ]

		replies = [ '@' + n.user.screen_name + ': ' + self.replier.analyse_tweet(n.text) + ' #ldnpydojo' for n in m ]

		for reply in replies:
			try:	
				self.tweet(reply)
			except tweepy.TweepError:
				pass
		
		"""for t,r in zip(texts,replies):
			print t
			print '=> ' + r"""

	def search(self):
		m = self.api.search('#ldnpydojo')
		
		#replies = [ '@' + n.user.screen_name + ': ' + self.replier.analyse_tweet(n.text) + ' #ldnpydojo' for n in m ]

		return m
Example #5
0
	def __init__(self):
		self.CONSUMER_KEY = '4qhVwgXY2ZZvbEN2qGTzdw'
		
		self.CONSUMER_SECRET = 'OdfyJE3NUpckodvGDw3fJmzivSz2xDdKd7ZDsNsf0Q'
		#self.ACCESS_KEY = '510800394-Zep39CczM0HKUGYKC5R5G2vlLzWyA2aJZxVx9Dx5'
		#self.ACCESS_SECRET = 'hHZdSFabzArRNQ0cQwrNGXcbCIdGNcUgGQ7qCD3c0'
		
		self.ACCESS_KEY = '510800394-Z7eeQiLIZOCccMbjyPElbSRyQb9SiezBax2C4tHq'
		self.ACCESS_SECRET = 'ioVceYgrfaPJ1sYCSXhdOqLef9przgmRCBhDg9Q'
		
		auth = tweepy.OAuthHandler(self.CONSUMER_KEY, self.CONSUMER_SECRET)
		auth.set_access_token(self.ACCESS_KEY, self.ACCESS_SECRET)
		self.replier = Replier()		
		
		self.api = tweepy.API(auth)
Example #6
0
    def run(self):

        quit = False
        conn_queue = Queue()

        logger.log('Dispatcher: {} init'.format(self.dis_id), "info",
                   'fs-server', self.log_queue)

        # Create Replier thread to handle connections
        # and responses from the Executor
        rep = Replier(self.res_queue, conn_queue, self.log_queue)
        rep.start()

        while not quit:

            try:
                # Accept client connection
                client_connection, client_address = self.server_socket.accept()

                logger.log(
                    'Received connection: {}, in worker: {}'.format(
                        client_address, self.dis_id), "debug", 'fs-server',
                    self.log_queue)

                # Parse request
                req_header, req_body = protocol.decode_request(
                    client_connection)

                # Send request to Executor
                self.req_queue.put(
                    (req_header, req_body, self.dis_id, client_address))

                # Send connection to Replier
                conn_queue.put(client_connection)

            except KeyboardInterrupt:
                quit = True

        # Wait for response thread to finish
        conn_queue.put(None)
        rep.join()

        self.server_socket.close()
Example #7
0
    def delay_task(self, delay, thread):
        self.delay = delay
        self.thread = thread


cfg = load_config()
if cfg["bot_token"] == None:
    print("Please set the bot_token in the config.json file!")
    exit()

random.seed()
client = discord.Client()
async_queue = list()
scheduler = Scheduler()
io = DiscordIO(async_queue, client)
replier = Replier(io, cfg)
mk = MarioKartManager(io, replier, scheduler, cfg)


@client.event
async def on_ready():
    print("Logged in as:")
    print(client.user.name)
    print(client.user.id)
    print("---")


@client.event
async def on_message(msg):
    if msg.content.startswith("=q"):
        exit()
Example #8
0
            response = Response(response.text, response.status_code,
                                response.headers.items())

        print(time.time() - start)
        return response

    else:
        best_option = 0
        response = requests.request(method='POST',
                                    url=app.BSN,
                                    headers={
                                        'Authorization':
                                        request.headers['Authorization'],
                                        'Content-Type':
                                        request.headers['Content-Type']
                                    },
                                    data=f'{{"option": {best_option} }}',
                                    cookies=request.cookies)
        response = Response(response.text, response.status_code,
                            response.headers.items())

        return response


if __name__ == '__main__':
    nlp = spacy.load('./bandersnatch_nlu')
    evaluator = Evaluator(nlp)
    replier = Replier(nlp)
    BSN = 'https://playscenario.dscvit.com/api/bandersnatch/play'
    app.run(debug=True)