Code Monkey home page Code Monkey logo

test_bot's Introduction

Проект Тест_БОТ

Тест_БОТ - это бот для Telegram, который служит испытательным образцом для пройденого материала на курсах Learn Python.

Установка

  1. Копируйте репозиторий с github
  2. Создайте виртуальное окружение
  3. Установите зависимости 'pip install -r requirements.txt'
  4. Саздайте файлик 'settings.py'
  5. Впишите в файлик settings.py переменные:
API_KEY = "ваш Telegram Token от BotFather"
USER_EMOJI = [":smiley_cat:", ":smiling_imp:", ":panda_face:", ":dog:"]
  1. Запустите бота командой 'python test_bot.py'

test_bot's People

Contributors

igv52 avatar

Watchers

 avatar

test_bot's Issues

Ревью

test_bot/utils.py

Lines 69 to 174 in 70c490a

def check_symbol(city):
wrong_char = ("Ъ", "ь", "ы", "й")
for char in city[::-1]:
if char in wrong_char:
continue
else:
break
else:
raise RuntimeError
return char
def check_user_char(arg1,user, city):
message = []
message.append(arg1)
message.append(user)
message.append(city)
check_char = open_game_city()
check_content = len(list(check_char))
if check_content >= 1:
for user_line in check_char:
user_search = user_line.split(',')
if user in user_search:
for line in check_char:
line = line.split(',')
if user in line:
user_city = city
last_city = check_symbol(line[2])
if last_city != format_city(user_city[0]):
message[0] = False
message[2] = last_city.upper()
else:
message
return message
def search_city(user, city):
arg1 = True
check_char = check_user_char(arg1,user, city)
city = format_city(city)
check = check_base_game(user, city, arg1)
if check_char[0]:
if check:
cities = open_base_city()
for line_user in cities:
line_user = format_city(line_user)
if line_user in city:
variant_bot = city
variant_bot = check_symbol(variant_bot)
for line_bot in cities:
line_bot = format_city(line_bot)
if line_bot[0] == variant_bot and check_base_game(user, city, line_bot):
message = line_bot
create_base_use_city(user, city, message)
break
else:
message = 'Этот город был'
else:
message = f'Вашь город должен начинаться на {check_char[2]}'
return message.capitalize()
def check_base_game(user, city, arg1):
line_bot = arg1
with open('city_game.csv', 'r', encoding='utf-8') as f:
cities = [city for city in f.readlines() if city.strip()]
good = True
for line in cities:
lines = line.replace('\n', '').split(',')
if lines[0] == str(user) and lines[1] == city:
good = False
break
if lines[0] == str(user) and lines[2] == line_bot:
good = False
break
return good
def format_city(city):
return city.strip().lower().replace('ё','е').replace('\n',"")
def open_base_city():
with open("city.txt", "r", encoding='utf-8') as f:
cities = {format_city(city) for city in f.readlines() if city.strip()}
return cities
def open_game_city():
with open("city_game.csv", "r", encoding='utf-8') as f:
cities = [format_city(city) for city in f.readlines() if city.strip()]
return cities
def create_base_use_city(user, city, bot_city):
with open("city_game.csv", "r+", encoding='utf-8') as f:
fields = ["user_id", "user_city", "bot_city"]
writer = csv.DictWriter(f, fieldnames=fields)
writer.writerow({'user_id' : user, 'user_city' : city, 'bot_city' : bot_city})
cities = [format_city(city) for city in f.readlines() if city.strip()]
return cities
def check_city(city_check):
city_check = city_check.lower()
cities = open_base_city()
print(city_check)
for city in cities:
if city == city_check:
proverka = 1
break
else:
proverka = 0
return proverka

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.