1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
| import requests
import json
import time
import os
from datetime import datetime, timedelta, timezone
from telebot import TeleBot
import logging
import urllib.parse
import telebot.apihelper
# Define the URLs
LINE_URL = "https://1xbet.com/LineFeed/Get1x2_VZip?count=100&lng=en&mode=1"
LIVE_URL = "https://1xbet.com/LiveFeed/Get1x2_VZip?count=100&lng=en&mode=1"
# Set up proxies
PROXIES = {
"http": "http://huws1i7s:zVCnuDv8@166.1.148.125:64198", #doesn't work now
"https": "http://huws1i7s:zVCnuDv8@166.1.148.125:64198" #doesn't work now
}
telebot.apihelper.proxy = None
# Set up logging
logging.basicConfig(filename='1xbet/src/bot.log', level=logging.DEBUG, format='%(asctime)s %(message)s')
# Define paths for output files
LINE_ACCEPTED_PATH = "1xbet/src/line_accepted.json"
LIVE_ACCEPTED_PATH = "1xbet/src/live_accepted.json"
# Bot token and chat IDs
BOT_1_TOKEN = '7799923puDkYyeo81L6QtZ8Iug'
BOT_2_TOKEN = '77744720Tz2X_stamy7fgmXX7s'
CHAT_ID = "360873117"
bot_1 = TeleBot(BOT_1_TOKEN)
bot_2 = TeleBot(BOT_2_TOKEN)
# Helper function to write JSON data to a file
def write_json_file(path, data):
with open(path, 'w') as f:
json.dump(data, f, indent=4)
# Helper function to read JSON data from a file
# Helper function to read JSON data from a file
def read_json_file(path):
if os.path.exists(path):
with open(path, 'r') as f:
return json.load(f)
return []
def normalize_name(name):
return name.strip().lower().replace(' ', '-')
def construct_line_event_link(event):
try:
base_url = "https://1xbet.com/en/line"
sport_name = normalize_name(event.get("SN", ""))
tournament_id = event.get("LI")
tournament_name = normalize_name(event.get("L", ""))
event_id = event.get("I")
team_1 = normalize_name(event.get("O1", ""))
team_2 = normalize_name(event.get("O2", ""))
# Create slugs for sport, tournament, and teams
sport_slug = urllib.parse.quote_plus(sport_name.replace(' ', '-'))
tournament_slug = urllib.parse.quote_plus(f"{tournament_id}-{tournament_name.replace(' ', '-')}")
teams_slug = urllib.parse.quote_plus(f"{event_id}-{team_1.replace(' ', '-')}-{team_2.replace(' ', '-')}")
# Construct the event URL
event_url = f"{base_url}/{sport_slug}/{tournament_slug}/{teams_slug}"
return event_url
except Exception as e:
logging.warning(f"Could not construct line event link for event {event.get('I')}: {e}")
return "https://1xbet.com/en/line"
# Function for parsing line data
def parse_line():
try:
# Load existing accepted events
existing_accepted = read_json_file(LINE_ACCEPTED_PATH)
live_accepted = read_json_file(LIVE_ACCEPTED_PATH)
response = requests.get(LINE_URL, proxies=PROXIES)
response.raise_for_status()
data = response.json().get('Value', [])
accepted = []
# Move matches that have started to live_accepted
for event in existing_accepted:
start_time = datetime.fromtimestamp(event.get('start_time', 0), tz=timezone.utc)
if start_time <= datetime.now(timezone.utc):
live_accepted.append(event)
else:
accepted.append(event)
# Add new matches
for event in data:
sport = event['SN']
tournament = event['L']
team1 = event['O1']
team2 = event['O2']
coefficients = event['E']
start_time = datetime.fromtimestamp(event['S'], tz=timezone.utc)
# Filtering triggers
triggers = [coef for coef in coefficients if coef['T'] in [1, 3, 4, 6] and 1.001 <= coef['C'] <= 1.2]
if triggers:
accepted_event = {
"sport": sport,
"tournament": tournament,
"team1": team1,
"team2": team2,
"coefficients": [{"T": coef['T'], "C": coef['C']} for coef in coefficients if coef['T'] in [1, 3, 4, 6]],
"triggers": triggers,
"link": construct_line_event_link(event),
"start_time": event['S']
}
accepted.append(accepted_event)
# Write updated list to file
write_json_file(LINE_ACCEPTED_PATH, accepted)
write_json_file(LIVE_ACCEPTED_PATH, live_accepted)
logging.info("Parsed line data successfully")
except Exception as e:
logging.error(f"Failed to parse line data: {str(e)}")
bot_1.send_message(chat_id=CHAT_ID, text=f"Error in line parsing: {str(e)}")
# Function for parsing live data
def parse_live():
try:
response = requests.get(LIVE_URL, proxies=PROXIES)
response.raise_for_status()
data = response.json().get('Value', [])
live_accepted = read_json_file(LIVE_ACCEPTED_PATH)
updated_live_accepted = []
for event in data:
sport = event['SN']
tournament = event['L']
team1 = event['O1']
team2 = event['O2']
coefficients = event['E']
# Check if event exists in live_accepted
for live_event in live_accepted:
if live_event['tournament'] == tournament and live_event['team1'] == team1 and live_event['team2'] == team2:
accepted_event = {
"sport": sport,
"tournament": tournament,
"team1": team1,
"team2": team2,
"coefficients": [{"T": coef['T'], "C": coef['C']} for coef in coefficients if coef['T'] in [1, 3, 4, 6]],
"triggers": live_event['triggers'],
"link": live_event['link'],
"start_time": live_event['start_time']
}
updated_live_accepted.append(accepted_event)
write_json_file(LIVE_ACCEPTED_PATH, updated_live_accepted)
logging.info("Parsed live data successfully")
except Exception as e:
logging.error(f"Failed to parse live data: {str(e)}")
bot_1.send_message(chat_id=CHAT_ID, text=f"Error in live parsing: {str(e)}")
# Function for monitoring triggers and sending notifications
def monitor_triggers():
try:
live_accepted = read_json_file(LIVE_ACCEPTED_PATH)
notified_triggers = set()
for event in live_accepted:
for trigger in event['triggers']:
coefficient = next((coef for coef in event['coefficients'] if coef['T'] == trigger['T']), None)
if coefficient:
trigger_key = (event['team1'], event['team2'], trigger['T'], '1.42')
if coefficient['C'] > 1.42 and trigger_key not in notified_triggers:
def send_message_with_retries(bot, chat_id, message, retries=3, delay=5):
for attempt in range(retries):
try:
bot.send_message(chat_id=chat_id, text=message)
return
except requests.exceptions.ProxyError as e:
if attempt < retries - 1:
logging.warning(f"Proxy error encountered. Retrying in {delay} seconds... (Attempt {attempt + 1}/{retries})")
time.sleep(delay)
else:
logging.error(f"Failed to send message after {retries} attempts: {e}")
bot_1.send_message(chat_id=CHAT_ID, text=
f"Trigger crossed 1.42:\n"
f"{event['tournament']}. {event['sport']}.
"
f"{event['team1']} - {event['team2']}\n"
f"Trigger: {trigger['T']}, Coefficient: {coefficient['C']}\n"
f"Link: {event['link']}"
)
notified_triggers.add(trigger_key)
trigger_key = (event['team1'], event['team2'], trigger['T'], '2')
if coefficient['C'] > 2 and trigger_key not in notified_triggers:
bot_2.send_message(chat_id=CHAT_ID, text=
f"Trigger crossed 2:"
f"{event['tournament']}. {event['sport']}."
f"{event['team1']} - {event['team2']}"
f"Trigger: {trigger['T']}, Coefficient: {coefficient['C']}"
f"Link: {event['link']}"
)
notified_triggers.add(trigger_key)
logging.info("Monitoring completed")
except Exception as e:
logging.error(f"Failed to monitor triggers: {str(e)}")
bot_1.send_message(chat_id=CHAT_ID, text=f"Error in monitoring: {str(e)}")
if __name__ == "__main__":
while True:
parse_line()
time.sleep(5)
parse_live()
time.sleep(5)
monitor_triggers() |