This repository has been archived by the owner on Oct 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
99 lines (75 loc) · 3.31 KB
/
main.py
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
# -*- coding: UTF-8 -*-
import logging
import time
import telegram
from apscheduler.schedulers.background import BackgroundScheduler
from telegram import (InlineKeyboardButton, InlineKeyboardMarkup,
ReplyKeyboardMarkup, ReplyKeyboardRemove, Update)
from telegram.ext import (CallbackContext, CallbackQueryHandler,
CommandHandler, ConversationHandler, Filters,
MessageHandler, Updater)
import os
import requests
import asyncio
import aiohttp
#########################################################################################################################################################################################
TGTOKEN = '' # 可在@botfather处申请
#########################################################################################################################################################################################
bot = telegram.Bot(token=TGTOKEN)
updater = Updater(token=TGTOKEN, use_context=True)
dispatcher = updater.dispatcher
# logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.DEBUG)
logger = logging.getLogger(__name__)
#
checkAccount = range(1)
# preconfig
def start(update: Update, context: CallbackContext):
update.message.reply_text(text='Hi,我可以帮你检测Oracle账号状态,请输入你的账户名,每行一个。建议私聊使用', parse_mode='HTML')
return checkAccount
def checkAccount(update: Update, context: CallbackContext):
ret1 = update.message.text
accountList = str.splitlines(ret1)
accok = 0
for accountName in accountList:
#update.message.reply_text(text='账号' + accountName + '返回状态码'+checkAccountIfActive(accountName))
if checkAccountIfActive(accountName) == 200:
accok = accok + 1
elif checkAccountIfActive(accountName) == 000:
update.message.reply_text(text='账号' + accountName + '似乎不存在或者已被封号')
elif checkAccountIfActive(accountName) == 503:
update.message.reply_text(text='账号' + accountName + '似乎已被封号')
else:
update.message.reply_text(text='账号' + accountName + '返回了未知状态码,为' + checkAccountIfActive(accountName))
update.message.reply_text(text='本次正常账号共' + str(accok) + '个。', parse_mode='HTML')
return ConversationHandler.END
#async def getAccountCode(accountName):
# async with aiohttp.ClientSession() as session:
# async with session.get('http://httpbin.org/get') as resp:
# print(resp.status)
def checkAccountIfActive(accountName):
try:
tmp1=requests.get('https://myservices-' + accountName + '.console.oraclecloud.com/mycloud/cloudportal/gettingStarted',timeout=5)
retcode=tmp1.status_code
except requests.exceptions.ConnectionError:
retcode=000
return retcode
def cancel(update: Update, context: CallbackContext):
return ConversationHandler.END
def main():
conv_handler = ConversationHandler(
entry_points=[CommandHandler('start', start)],
states={
checkAccount: [MessageHandler(Filters.chat_type.private & Filters.text, checkAccount)],
},
fallbacks=[CommandHandler('cancel', cancel)],
conversation_timeout=60.0
)
dispatcher.add_handler(conv_handler)
#
updater.start_polling()
updater.idle()
# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
main()