<commit_before># coding=UTF-8

# General modules.
import os, os.path
import logging
import sys
from threading import Timer
import string
import random

import feedparser
import urllib
import urllib2
import requests
from lxml import html
import duckduckgo



class Bot(object):

    def __init__(self, master):
        self.master = master
    
    
    def sum_func(self, message):
        sum_n = 0
        for i in self.command[1:]:
            sum_n += int(i)
    
        message["body"] = sum_n
        message["from"] = 'Bot'
        self.master.send_massage(message)
    
    def mean_func(self, message):
        sum_n = 0
        m = 0
        for i in self.command[1:]:
            sum_n += int(i)
            m += 1
    
        message["body"] = sum_n/m
        message["from"] = 'Bot'
        self.master.send_massage(message)
    
    def news_func(self, message):
        news = feedparser.parse('http://news.ycombinator.com/rss')
    
        for i in range(2, 12):
            message["body"] = news.entries[i].title
            message["from"] = 'Bot'
            self.master.send_massage(message)
    
    
    #def duck_func(self, message):
        #url = "http://duckduckgo.com/html"
        #data = urllib.urlencode({'q': 'Python'})
        #results = urllib2.urlopen(url, data)       
    
        ##find = 'http://duckduckgo.com/?q='+self.command[1]
        ##for i in self.command[2:]:
        ##    find += '+'+i
    
        ##find +='&ia=about'    
    
        ##found = feedparser.parse(find)
    
        ##for i in range(2, 11):
        #message["body"] = str(results.read(10))
        #message["from"] = 'Bot'
        #self.send_massage(message)
    
    
    #def duck_func(self, message):
        #url = 'http://duckduckgo.com/html/'
        #params = {
            #'q': 'Python',
            #'s': '0',
        #}
    
        #res = requests.post(url, data=params)
        #doc = html.fromstring(res.text)
    
        #results = [a.get('href') for a in doc.cssselect('#links .links_main a')]
        ##for result in results:
        #message["body"] = results[1]
        #message["from"] = 'Bot'
        #self.send_massage(message)
    
    
    
    
    def duck_func(self, message):
    
        r = duckduckgo.query(str(message["body"])[5:])
        for i in range(0,10):
            message["body"] = r.related[i].text
            message["from"] = 'Bot'
            self.master.send_massage(message)       
    
    def makeBot(self, message):
    
        #split command by spaces    
    
        self.command = message["body"].lower().split(' ')
    
        try:
            self.com_dict[self.command[0]](self, message)
        except KeyError:
            self.master.write_message({'error': 1, 'textStatus': 'Error: wrong command'})
    
        return
    
    com_dict = {'!sum': sum_func, '!mean': mean_func, '!news': news_func, '!duck': duck_func}<commit_msg>bot correct<commit_after># coding=UTF-8

# General modules.
import os, os.path
import logging
import sys
from threading import Timer
import string
import random

import feedparser
import urllib
import urllib2
import requests
from lxml import html
import duckduckgo



class Bot(object):

    def __init__(self, master):
        self.master = master
        
        self.message = {
            '_id': '',
            'from': '',
            'body': '',
        }        
    
    
    def sum_func(self):
        sum_n = 0
        for i in self.command[1:]:
            sum_n += int(i)
    
        self.send_bot(sum_n)
    
    def mean_func(self):
        sum_n = 0
        m = 0
        for i in self.command[1:]:
            sum_n += int(i)
            m += 1
    
        self.send_bot(sum_n/m)
    
    def news_func(self):
        news = feedparser.parse('http://news.ycombinator.com/rss')
    
        for i in range(2, 12):
            self.send_bot(news.entries[i].title)
    
    
    #def duck_func(self, message):
        #url = "http://duckduckgo.com/html"
        #data = urllib.urlencode({'q': 'Python'})
        #results = urllib2.urlopen(url, data)       
    
        ##find = 'http://duckduckgo.com/?q='+self.command[1]
        ##for i in self.command[2:]:
        ##    find += '+'+i
    
        ##find +='&ia=about'    
    
        ##found = feedparser.parse(find)
    
        ##for i in range(2, 11):
        #message["body"] = str(results.read(10))
        #message["from"] = 'Bot'
        #self.send_massage(message)
    
    
    #def duck_func(self, message):
        #url = 'http://duckduckgo.com/html/'
        #params = {
            #'q': 'Python',
            #'s': '0',
        #}
    
        #res = requests.post(url, data=params)
        #doc = html.fromstring(res.text)
    
        #results = [a.get('href') for a in doc.cssselect('#links .links_main a')]
        ##for result in results:
        #message["body"] = results[1]
        #message["from"] = 'Bot'
        #self.send_massage(message)
    
    
    
    
    def duck_func(self):
    
        r = duckduckgo.query(str(self.message["body"])[5:])
        for i in range(0,10):
            self.send_bot(r.related[i].text)
            
            
    def send_bot(self, body,  n_user = 'Bot'):
        self.message["body"] = body
        self.message["from"] = n_user
        self.master.send_massage(self.message)        
    
    def makeBot(self, message):
    
        #split command by spaces    
    
        self.command = message["body"].lower().split(' ')
        self.message = message
    
        try:
            self.com_dict[self.command[0]](self)
        except KeyError:
            self.master.write_message({'error': 1, 'textStatus': 'Error: wrong command'})
    
        return
    
    com_dict = {'!sum': sum_func, '!mean': mean_func, '!news': news_func, '!duck': duck_func}
{'fraction_non_alphanumeric': 0.14467572681919835, 'fraction_numerical': 0.009289523481851024, 'mean_word_length': 1.814133591481123, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4448287', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1906, 'n_words': 395}