<commit_before># -*- coding: utf-8 -*-

# VK Bot by Ax3 (<NAME>) 
# vk.com/ax3effect

# Main Modules
import vk
import time, threading
import requests
import simplejson as json
import ast
import traceback
import random
import re
#from PIL import Image
import io

try:
    import dataset
    database_enable = 1
except ImportError:
    print("No module 'dataset'. Database statistics disabled")
    database_enable = 0
from datetime import datetime
from random import randint
from configobj import ConfigObj




import urllib.request



#### Settings
customMsg = "\n // vk.com/ax3bot "
show_names = 0 # 1 or 0, disable it for better performance
blacklist = [1,2,3,4] # blacklist, VK ID's
chat_blacklist = [] # chat blacklist, VK Chat ID's
albumID = 203267618 # album for uploading photos, ID
ownerID = 10399749 # owner ID
#database_enable = 0  #override database setting

#### Settings

#### Config files
config = ConfigObj("settings.ini")
vk_access_token = config['vk_token']
geocodingAPI = config['google_geocoding']
forecastioAPI = config['forecastio']
#### Config files

print("Initializing...")

#### Help messages
helpMessage = (" - Помощь - \n"
    "test \n"
    "привет \n"
    "курс \n"
    "погода (ГОРОД) \n"
    "сосчитать (13 * 37) \n"
    "правда (что-то) \n"
    "статистика \n"
    "баш"
    "падик"
    )

#### Text messages variables
msg_test = ["test", "тест"]
msg_help = ["help", "помощь"]
msg_hi = ["hi", "привет"]
msg_exchange = ["курс", "exchange", "rates"]
msg_weather = ["weather", "погода", "Погода"]
msg_calc = ["calc", "сосчитать", "сч"]
msg_truth = ["truth", "правда", "Правда"]
msg_stats = ["stats", "статистика"]
msg_imagetest = ["image", "имага"]
msg_publictest = ["publ", "systest"]
msg_autochatmode1on = ["!мат_вкл"]
msg_autochatmode1off = ["!мат_выкл"]
msg_bashorg = ["баш"]
msg_padik = ["падик"]


attempt_id = 0
chat_id = 0
weather_disable = 0 
autoChatMode = 0

connect_success = 0

if database_enable == 1:
    def database(vid, vname):
        db = dataset.connect('sqlite:///vkcount2.db')
        global table
        table = db['user']
        checkExist = table.find_one(vid=vid)
        try:
            #print checkExist["vcount"]
            if checkExist["vcount"] or checkExist["vcount"] == 0:
                ccount = checkExist["vcount"] + 1
                #print "CCOUNT - " + str(ccount)
                table.update(dict(vid=vid, vcount=ccount), ['vid'])
        except Exception:
            print("New user " + str(vid))
            table.insert(dict(vid=vid, vname=vname, vcount=0))
        #for user in db['user']:
            #print "ID : " + str(user['vid']) 
            #print "VCOUNT : " + str(user['vcount'])


def downloadImage(url):
    image_name = 'photo.jpg'
    urllib.request.urlretrieve(url, image_name)



vkapi = vk.API(access_token=vk_access_token)
asd = vkapi.messages.getLongPollServer(use_ssl = 0)

def chatidcheck(chatcheck):
	chatcheckid = str(chatcheck)[-2:]
	return chatcheckid

def msgcheck(msg):
    global autoChatMode
    global chat_id
    global attempt_id
    attempt_id = attempt_id + 1 # VK anti-block system
    msg = str(msg)
    if msg.split(' ')[0] in msg_test:
        vk_message = "Рандом: {}".format(str(randint(2,100))) + "%."
        msgsend(userid, vk_message, chat_id)
    elif msg.split(' ')[0] in msg_help:
        msgsend(userid, helpMessage, chat_id)
    elif msg.split(' ')[0] in msg_hi:
        vk_message = "Привет!" 
        msgsend(userid, vk_message, chat_id)
    elif msg.split(' ')[0] in msg_exchange:
        kurs = requests.get("http://api.fixer.io/latest?base=USD")
        kursbid1 = kurs.json()["rates"]
        kursbid = kursbid1["RUB"]
        kurs_euro = requests.get("http://api.fixer.io/latest?base=EUR")
        kursbid1_euro = kurs_euro.json()["rates"]
        kursbid_euro = kursbid1_euro["RUB"]
        vk_message = "1 доллар равен {} рублям. \n 1 евро равен {} рублям. ".format(kursbid, kursbid_euro)
        msgsend(userid, vk_message, chat_id)
    elif msg.split(' ')[0] in msg_weather:
        if weather_disable == 0:
            #print("got it!")
            msgGeoSplit = msg.split()
            msgGeoSplit = msgGeoSplit[1:]
            msgGeoString = ' '.join(msgGeoSplit)
            if msgGeoString == "":
                vk_message = "Описание:\n погода (город)"
                msgsend(userid, vk_message, chat_id)
            else:
                print(msgGeoString)
                geocodeURL = "https://maps.googleapis.com/maps/api/geocode/json?address={}&key={}".format(msgGeoString, geocodingAPI)
                print(geocodeURL)
                geocodeRequest = requests.get(geocodeURL)
                geoResult2 = geocodeRequest.json()

                if geoResult2["status"] == "OK":
                    geoResult = geoResult2["results"]
                    geoLocation1 = geoResult[0]["geometry"]
                    geoLocation2 = geoLocation1["location"]
                    geoLat = geoLocation2["lat"]
                    geoLng = geoLocation2["lng"]
                    print("Lat: {}, Lng: {}".format(geoLat, geoLng))

                    forecastURL = "https://api.forecast.io/forecast/{}/{},{}?units=si".format(forecastioAPI, geoLat, geoLng)
                    #print forecastURL
                    forecastGet = requests.get(forecastURL)
                    forecastJSON = forecastGet.json()
                    #print forecastJSON
                    forecastp1 = forecastJSON["currently"]
                    forecastp2 = forecastp1["temperature"]
                    forecastp2Summary = forecastp1["summary"]
                    forecastp2Windspeed = forecastp1["windSpeed"]
                    forecastp2Hum = forecastp1["humidity"]
                    forecastp2Pressure = forecastp1["pressure"]
                    vk_message = "Погода: {}\nLat: {}, Lng: {} \nhttp://maps.google.co.uk/maps/@{},{},16z \n Температура воздуха: {}°C \n {} \n Скорость ветра: {}м/c \n Влажность: {}% \n Давление: {} мм. рт. ст.".format(msgGeoString, geoLat, geoLng, geoLat, geoLng, forecastp2, forecastp2Summary, forecastp2Windspeed, forecastp2Hum*100, forecastp2Pressure)
                    msgsend(userid, vk_message, chat_id)

                else:
                    vk_message = "Не знаю такого места!"
                    msgsend(userid, vk_message, chat_id)



            #vk_message = "successful!"
            #msgsend(userid, vk_message, chat_id)
    elif msg.split(' ')[0] in msg_calc:
        msgCalc = msg.split()
        msgCalc = msgCalc[1:]
        try:
            if msgCalc[1] == "+":
                msgCalcResult = int(msgCalc[0]) + int(msgCalc[2])
                vk_message = "Результат: {}".format(msgCalcResult)
                msgsend(userid, vk_message, chat_id)
            elif msgCalc[1] == "-":
                msgCalcResult = int(msgCalc[0]) - int(msgCalc[2])
                vk_message = "Результат: {}".format(msgCalcResult)
                msgsend(userid, vk_message, chat_id)
            elif msgCalc[1] == "*":
                msgCalcResult = int(msgCalc[0]) * int(msgCalc[2])
                vk_message = "Результат: {}".format(msgCalcResult)
                msgsend(userid, vk_message, chat_id)
            elif msgCalc[1] == "/":
                msgCalcResult = int(msgCalc[0]) / int(msgCalc[2])
                vk_message = "Результат: {}".format(msgCalcResult)
                msgsend(userid, vk_message, chat_id)
            else:
                vk_message = "Неправильный ввод! Вы ввели: " + str(msg)
                msgsend(userid, vk_message, chat_id)
        except Exception:
            vk_message = "Неправильный ввод! Пример: 7 + 3, 51 / 3"
            msgsend(userid, vk_message, chat_id)
    elif msg.split(' ')[0] in msg_truth:
        pravdamsg = []<commit_msg>deleted unnecessary code, fixed bugs etc<commit_after># -*- coding: utf-8 -*-

# VK Bot by Ax3 (<NAME>) 
# vk.com/ax3effect

# Main Modules
import vk
import time, threading
import requests
import simplejson as json
import ast
import traceback
import random
import re
#from PIL import Image
import io

try:
    import dataset
    database_enable = 1
except ImportError:
    print("No module 'dataset'. Database statistics disabled")
    database_enable = 0
from datetime import datetime
from random import randint
from configobj import ConfigObj




import urllib.request



#### Settings
customMsg = "\n // vk.com/ax3bot "
show_names = 0 # 1 or 0, disable it for better performance
blacklist = [1,2,3,4] # blacklist, VK ID's
chat_blacklist = [] # chat blacklist, VK Chat ID's
albumID = 203267618 # album for uploading photos, ID
ownerID = 10399749 # owner ID
#database_enable = 0  #override database setting

#### Settings

#### Config files
config = ConfigObj("settings.ini")
vk_access_token = config['vk_token']
geocodingAPI = config['google_geocoding']
forecastioAPI = config['forecastio']
#### Config files

print("Initializing...")

#### Help messages
helpMessage = (" - Помощь - \n"
    "test \n"
    "привет \n"
    "курс \n"
    "погода (ГОРОД) \n"
    "сосчитать (13 * 37) \n"
    "правда (что-то) \n"
    "статистика \n"
    "баш"
    "падик"
    )

#### Text messages variables
msg_test = ["test", "тест"]
msg_help = ["help", "помощь"]
msg_hi = ["hi", "привет"]
msg_exchange = ["курс", "exchange", "rates"]
msg_weather = ["weather", "погода", "Погода"]
msg_calc = ["calc", "сосчитать", "сч"]
msg_truth = ["truth", "правда", "Правда"]
msg_stats = ["stats", "статистика"]
msg_imagetest = ["image", "имага"]
msg_publictest = ["publ", "systest"]
msg_autochatmode1on = ["!мат_вкл"]
msg_autochatmode1off = ["!мат_выкл"]
msg_bashorg = ["баш"]
msg_padik = ["падик"]


attempt_id = 0
chat_id = 0
weather_disable = 0 
autoChatMode = 0

connect_success = 0

if database_enable == 1:
    def database(vid, vname):
        db = dataset.connect('sqlite:///vkcount2.db')
        global table
        table = db['user']
        checkExist = table.find_one(vid=vid)
        try:
            #print checkExist["vcount"]
            if checkExist["vcount"] or checkExist["vcount"] == 0:
                ccount = checkExist["vcount"] + 1
                #print "CCOUNT - " + str(ccount)
                table.update(dict(vid=vid, vcount=ccount), ['vid'])
        except Exception:
            print("New user " + str(vid))
            table.insert(dict(vid=vid, vname=vname, vcount=0))
        #for user in db['user']:
            #print "ID : " + str(user['vid']) 
            #print "VCOUNT : " + str(user['vcount'])


def downloadImage(url):
    image_name = 'photo.jpg'
    urllib.request.urlretrieve(url, image_name)



vkapi = vk.API(access_token=vk_access_token)
asd = vkapi.messages.getLongPollServer(use_ssl = 0)

def chatidcheck(chatcheck):
	chatcheckid = str(chatcheck)[-2:]
	return chatcheckid

def msgcheck(msg):
    global autoChatMode
    global chat_id
    global attempt_id
    attempt_id = attempt_id + 1 # VK anti-block system
    msg = str(msg)
    if msg.split(' ')[0] in msg_test:
        vk_message = "Рандом: {}".format(str(randint(2,100))) + "%."
        msgsend(userid, vk_message, chat_id)
    elif msg.split(' ')[0] in msg_help:
        msgsend(userid, helpMessage, chat_id)
    elif msg.split(' ')[0] in msg_hi:
        vk_message = "Привет!" 
        msgsend(userid, vk_message, chat_id)
    elif msg.split(' ')[0] in msg_exchange:
        kurs = requests.get("http://api.fixer.io/latest?base=USD")
        kursbid1 = kurs.json()["rates"]
        kursbid = kursbid1["RUB"]
        kurs_euro = requests.get("http://api.fixer.io/latest?base=EUR")
        kursbid1_euro = kurs_euro.json()["rates"]
        kursbid_euro = kursbid1_euro["RUB"]
        vk_message = "1 доллар равен {} рублям. \n 1 евро равен {} рублям. ".format(kursbid, kursbid_euro)
        msgsend(userid, vk_message, chat_id)
    elif msg.split(' ')[0] in msg_weather:
        if weather_disable == 0:
            #print("got it!")
            msgGeoSplit = msg.split()
            msgGeoSplit = msgGeoSplit[1:]
            msgGeoString = ' '.join(msgGeoSplit)
            if msgGeoString == "":
                vk_message = "Описание:\n погода (город)"
                msgsend(userid, vk_message, chat_id)
            else:
                print(msgGeoString)
                geocodeURL = "https://maps.googleapis.com/maps/api/geocode/json?address={}&key={}".format(msgGeoString, geocodingAPI)
                print(geocodeURL)
                geocodeRequest = requests.get(geocodeURL)
                geoResult2 = geocodeRequest.json()

                if geoResult2["status"] == "OK":
                    geoResult = geoResult2["results"]
                    geoLocation1 = geoResult[0]["geometry"]
                    geoLocation2 = geoLocation1["location"]
                    geoLat = geoLocation2["lat"]
                    geoLng = geoLocation2["lng"]
                    print("Lat: {}, Lng: {}".format(geoLat, geoLng))

                    forecastURL = "https://api.forecast.io/forecast/{}/{},{}?units=si".format(forecastioAPI, geoLat, geoLng)
                    #print forecastURL
                    forecastGet = requests.get(forecastURL)
                    forecastJSON = forecastGet.json()
                    #print forecastJSON
                    forecastp1 = forecastJSON["currently"]
                    forecastp2 = forecastp1["temperature"]
                    forecastp2Summary = forecastp1["summary"]
                    forecastp2Windspeed = forecastp1["windSpeed"]
                    forecastp2Hum = forecastp1["humidity"]
                    forecastp2Pressure = forecastp1["pressure"]
                    vk_message = "Погода: {}\nLat: {}, Lng: {} \nhttp://maps.google.co.uk/maps/@{},{},16z \n Температура воздуха: {}°C \n {} \n Скорость ветра: {}м/c \n Влажность: {}% \n Давление: {} мм. рт. ст.".format(msgGeoString, geoLat, geoLng, geoLat, geoLng, forecastp2, forecastp2Summary, forecastp2Windspeed, forecastp2Hum*100, forecastp2Pressure)
                    msgsend(userid, vk_message, chat_id)

                else:
                    vk_message = "Не знаю такого места!"
                    msgsend(userid, vk_message, chat_id)

#

            #vk_message = "successful!"
            #msgsend(userid, vk_message, chat_id)
    elif msg.split(' ')[0] in msg_calc:
        msgCalc = msg.split()
        msgCalc = msgCalc[1:]
        try:
            if msgCalc[1] == "+":
                msgCalcResult = int(msgCalc[0]) + int(msgCalc[2])
                vk_message = "Результат: {}".format(msgCalcResult)
                msgsend(userid, vk_message, chat_id)
            elif msgCalc[1] == "-":
                msgCalcResult = int(msgCalc[0]) - int(msgCalc[2])
                vk_message = "Результат: {}".format(msgCalcResult)
                msgsend(userid, vk_message, chat_id)
            elif msgCalc[1] == "*":
                msgCalcResult = int(msgCalc[0]) * int(msgCalc[2])
                vk_message = "Результат: {}".format(msgCalcResult)
                msgsend(userid, vk_message, chat_id)
            elif msgCalc[1] == "/":
                msgCalcResult = int(msgCalc[0]) / int(msgCalc[2])
                vk_message = "Результат: {}".format(msgCalcResult)
                msgsend(userid, vk_message, chat_id)
            else:
                vk_message = "Неправильный ввод! Вы ввели: " + str(msg)
                msgsend(userid, vk_message, chat_id)
        except Exception:
            vk_message = "Неправильный ввод! Пример: 7 + 3, 51 / 3"
            msgsend(userid, vk_message, chat_id)
    elif msg.split(' ')[0] in msg_truth:
        pravdamsg = []
{'fraction_non_alphanumeric': 0.13492675404780263, 'fraction_numerical': 0.015034695451040863, 'mean_word_length': 2.396988214753383, 'pattern_counts': {'":': 12, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2378302', 'n_tokens_mistral': 5534, 'n_tokens_neox': 5284, 'n_words': 1103}