Skip to content

Commit 7517206

Browse files
committed
Version 0.1 is officially completed!
1 parent 8c4857d commit 7517206

6 files changed

Lines changed: 38 additions & 12 deletions

File tree

src/services/ads/repositories.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from services.common import CRUD, PaginationQuery
23
from .models import Ads
34
from fastapi import (
@@ -67,6 +68,8 @@ async def create(
6768
message.get("chat").get("id"),
6869
keywords
6970
)
71+
else:
72+
logging.error("Task not started; keywords={keywords}")
7073
return result
7174

7275

src/services/ads/tasks.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
from services.tel_users.repositories import TelegramCrud
33
from db import get_app_settings
44
import requests
5+
import logging
6+
57

68
class AdsManager(TelegramCrud, KeyWordCrud):
79
_context = None
@@ -13,7 +15,7 @@ def context(self):
1315
return self._context
1416

1517
def forward_message(self, message_id, from_chat_id, ads_keywords):
16-
print(ads_keywords)
18+
logging.info(f"ads_keywords={ads_keywords}")
1719
token = get_app_settings().telegram_token
1820
all_related_users = self.union_related_user_tech(ads_keywords)
1921
for user in all_related_users:
@@ -28,12 +30,11 @@ def forward_message(self, message_id, from_chat_id, ads_keywords):
2830
"from_chat_id": from_chat_id,
2931
"message_id": message_id
3032
}
31-
print(user)
32-
print(payload)
3333
url = f"https://api.telegram.org/bot{token}/forwardMessage"
3434
response = requests.post(url, json=payload)
35-
print(response.text)
36-
35+
if response.status_code != 200 or not response.json(
36+
).get("ok"):
37+
logging.error(response.text)
3738

3839

3940
async def send_message_to_filtered_users(

src/services/ads/utils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import requests
22
from db import get_app_settings
33
from typing import Union
4+
import logging
45

56

67
def send_message_to_telegram(
@@ -23,7 +24,7 @@ def send_message_to_telegram(
2324
json=payload
2425
)
2526
if resp.status_code != 200 or not resp.json()["ok"]:
26-
print(resp.text)
27+
logging.error(resp.text)
2728
return None
2829
else:
2930
return resp.json()["result"]

tel/bot.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ async def is_user_a_member(message: types.Message, channel_id=channel_id):
3131
)
3232

3333

34-
3534
@app.on_message(filters.command("show") & filters.private)
3635
async def show_keywords(_, message: types.Message):
3736
if await is_user_a_member(message):
@@ -50,6 +49,19 @@ async def show_keywords(_, message: types.Message):
5049
)
5150

5251

52+
@app.on_message(filters.command("info") & filters.private)
53+
async def get_info(_, message: types.Message):
54+
if await is_user_a_member(message):
55+
text = requests.get(
56+
f"http://main_app:8000/api/telegram/{int(message.from_user.id)}"
57+
).json().get("result")
58+
text = text[0] if len(text) == 1 else "No Query Found"
59+
await message.reply_text(
60+
text,
61+
reply_to_message_id=message.reply_to_message_id
62+
)
63+
64+
5365
@app.on_message(filters.command("start") & filters.private)
5466
async def welcome(_, message: types.Message):
5567
print("HEY!")
@@ -62,7 +74,9 @@ async def welcome(_, message: types.Message):
6274
Too easy! ```(django or fastapi) and (backend or (fullstack and vuejs) or (frontend and vuejs)) and germany```
6375
You only need 1 day of python knowledge to write your own logical expression :)
6476
Please use /show command to see all the possible namespaces and keywords you can filter.
65-
If you want to setup your filter, simply send it to me here.
77+
You may use /info to check your current query
78+
79+
If you want to setup your filter, simply write it to me here.
6680
6781
Remember, You must be a member of main channel to be able to use this bot:)
6882
@linkedin_python
@@ -91,8 +105,11 @@ async def start_filter(_, message: types.Message):
91105
)
92106
else:
93107
error = resp.get('error')
108+
text = f"Your query is not done correctly, because: {error}"
109+
text += "\n\nPlease write /show to see all available namspaces"
110+
text += "\n or /start to see the how-to-use guide!"
94111
await message.reply_text(
95-
f"Your query is not done correctly, because: {error}",
112+
text,
96113
reply_to_message_id=message.reply_to_message_id
97114
)
98115

worker/connection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,18 @@ async def create_ads(
9292
await helpers.safe_fill_form(
9393
chatgpt_page, xpaths.GPT_FILL,
9494
f"""
95-
KEYWORDS = '''{helpers.get_all_keywords()}'''
95+
PROMPT: Read the the text, then follow up the instructions that is given at the end.
9696
97-
{prompt.TAG_ADS}
97+
KEYWORDS = '''{helpers.get_all_keywords()}'''
9898
9999
Job Title: {title} \n
100100
Country: {country} \n
101101
Advertisement: \n
102102
{body}
103+
104+
\n \n
105+
{prompt.TAG_ADS}
106+
103107
""",
104108
timeout=5000
105109
)

worker/prompt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
\n
5555
INSTRUCTIONS: \n
5656
1. Read the keywords that i have sent you previously on top of this text. Read the advertisement that I'll send you in below. Detect the matching keywords with keywords I have sent you at first.\n
57-
2. Keyword the job as one of these options: `backend` `frontend` `devops` `software` `full_stack` or if none match, then label it as `others` \n
57+
2. Analyze the job from job title, and match it with: `backend` `frontend` `devops` `software` `full_stack` or if none match, then label it as `others` \n
5858
3. DO NOT CREATE KEYWORDS ON YOUR OWN. ONLY use the provided list of KEYWORDS \n
5959
4. Use the exact spelling and case of the KEYWORDS provided, as they are case-sensitive. \n
6060
5. Analyze the KEYWORDS I have sent you carefully. They usually follow python's namespacing rules. (e.g., "c#" to "c_sharp" or ".NET" to "dot_net"). Use the version of keyword I have provided for you \n

0 commit comments

Comments
 (0)