Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new category #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions app/parse_freelance_habr.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,64 @@ def parse_category(url, category):
#else:
# print(title)

def parse_category_price(url, category):
page = requests.get(url).content
soup = BeautifulSoup(page, "html.parser")
all_jobs = soup.findAll('article', {"class": "task task_list"})

for job in all_jobs:
title = job.find("div", "task__title").text
url = 'http://freelance.habr.com' + job.find("div", "task__title").find("a").get('href')

if not job_exist(url):
date = job.find("span", "params__published-at").text.splitlines()
date = str(date[0])

price_raw = job.find("div", "task__price")

#Провека цены, выше 100 000 руб
try:
price = price_raw.find("span", "count").text
price_temp = price.replace(' ', '', 1)
price_number = 0
for t in price_temp.split():
try:
num = int(t)
except ValueError:
pass

if(price_number < 100000):
continue
except:
continue

text_page = requests.get(url).content
text_soup = BeautifulSoup(text_page, "html.parser")
text = text_soup.find('div', {'class': 'task__description'}).text

text_length = 320
text = (text[:text_length] + '..') if len(text) > text_length else text

#print(text, "\n")

job_row = Job(
title = title,
date = date,
price = price,
url = url,
category = category,
parse_date = datetime.now(),
description = text
)

session.add(job_row)
session.commit()

#else:
# print(title)

parse_category(admin_url, 'admin')
parse_category(webdev_url, 'webdev')
parse_category(webdis_url, 'webdis')
parse_category(dev_url, 'dev')
parse_category_price(default_url, 'up100')
30 changes: 29 additions & 1 deletion bot/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def handle_list(message):
return
text = '\U0001f1f7\U0001f1fa /freelansim -- Last job from freelansim.ru\n'+\
'\U0001f1f7\U0001f1fa /freelancehunt -- Last job from freelansim.ru\n'+\
'\U0001f1fa\U0001f1f8 /freelancecom -- Last job from freelance.com'
'\U0001f1fa\U0001f1f8 /freelancecom -- Last job from freelance.com\n' +\
'\U0001f1fa\U0001f1f1 /freelanceupper100K -- Last job upper 100K rub'

bot.send_message(message.chat.id, text)

Expand Down Expand Up @@ -66,6 +67,7 @@ def handle_freelansim(message):
'\u2692 /freelansim_webdev - Last jobs for Web Developers\n'+\
'\U0001f307 /freelansim_webdis - Last jobs for Web Designers\n'+\
'\U0001f6e0 /freelansim_dev - Last jobs for Developers'
'\U0001f6e0 /freelansim_upper100 - Last jobs for Developers'
bot.send_message(message.chat.id, output)

@bot.message_handler(commands=['freelancehunt', 'fch'])
Expand Down Expand Up @@ -96,6 +98,10 @@ def handle_freelansim_webdis(msg):
def handle_freelansim_dev(msg):
send_jobs('freelansim', 'dev', msg.chat.id)

@bot.message_handler(commands=['freelansim_upper100'])
def handle_freelansim_upper100(msg):
send_jobs('freelansim', 'up100', msg.chat.id)

@bot.message_handler(commands=['freelance_adm', 'fca'])
def handle_freelansim_adm(msg):
send_jobs('freelance.com', 'admin', msg.chat.id)
Expand Down Expand Up @@ -216,6 +222,28 @@ def handle_webdesign_subscribe(message):
'\nYou subscribed on Web Design category'
bot.send_message(message.chat.id, output)

@bot.message_handler(commands=['subscribe_up100','su'])
def handle_upper100_subscribe(message):
# if user doesn't exist
if not user_exist(message.from_user.id):
Subscription().add_new(message.from_user.username, message.from_user.id, 'up100', session)
else: # else update existing subscription
try:
Subscription().update(message.from_user.id, 'up100', session)
session.commit()
except:
session.rollback()
raise
finally:
session.close()

output = 'Chat ID: ' + str(message.chat.id) + \
'\nUser ID: ' + str(message.from_user.id) + \
'\nNick: ' + str(message.from_user.username) + \
'\nLast JOB ID in this category: ' + str(get_last_job('up100')) + \
'\n*You subscribed on upper 100 000 category*'
bot.send_message(message.chat.id, output)

@bot.message_handler(content_types=["text"])
def repeat_all_messages(message): # Название функции не играет никакой роли, в принципе
print(message.chat.id)
Expand Down