def isminecraft(addr, timeout=5):
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(addr)
s.settimeout(timeout)
buf = struct.pack('xBB', 4, len(addr[0].encode('utf-8')))
buf += addr[0].encode('utf-8')
buf += struct.pack('HB', addr[1], 1)
pkt = struct.pack('B', len(buf))
pkt += buf
pkt += b'\x01\x00'
s.send(pkt)
try:
bufsize = struct.unpack('B', s.recv(3)[2:])[0]
js = s.recv(bufsize, socket.MSG_WAITALL)
except socket.timeout:
return (False, None)
try:
response = json.loads(js)
version = response['version']['name']
return (True, version)
except (ValueError, KeyError):
return (False, None)
addrs = [
('192.168.99.100', 22508),
('192.168.99.100', 32761),
]
for addr in addrs:
isok, version = isminecraft(addr)
if isok:
print('[%s] Minecraft version: %s' % (str(addr), version))
message.chat.id
является числом, поэтому все строки из users.txt Вам необходимо привести к числовому типу.with open('users.txt', 'r') as fp:
user_ids = [int(l) for l in fp.readlines()]
@bot.message_handler(func=lambda message: message.chat.id not in user_ids)
def access_msg(message):
bot.send_message(message.chat.id, 'No Access!')
$ pipenv lock -r > requirements.txt
$ pip install -U pipenv-to-requirements
$ pipenv run pipenv_to_requirements
from aiohttp import web
async def get_list(request):
list_id = request.match_info['list_id']
page = request.query.get('page', 1)
text = 'List {} with page {}'.format(list_id, page)
return web.Response(text=text)
app = web.Application()
app.router.add_get('/lists/{list_id}', get_list)
web.run_app(app)
access_token
и refresh_token
.var GlobalSessions *session.Manager
func test(){
sess, _ := GlobalSessions.SessionStart(c.Ctx.ResponseWriter, c.Ctx.Request)
}
func main() {
var globalSessions, _ = session.NewManager("memory", conf)
go globalSessions.GC()
admin.GlobalSessions = globalSessions
}
- n
|-- base.py
- settings
|-- local.py
|-- production.py
ln -sf n/base.py settings/base.py
.from .base import *
syntax = "proto3";
package entity;
message Entity {
// Kinds:
//
// * kaboom
// * oops
string kind = 1;
message Kaboom { uint64 data = 1; }
message Oops { uint64 data = 1; }
Kaboom kaboom = 2;
Oops oops = 3;
}
package main
import (
"github.com/golang/protobuf/proto"
"pathtopkg/entity"
)
func main() {
var e entity.Entity
err := proto.Unmarshal(buf, &e)
if err != nil {
panic(err)
}
switch e.Kind {
case "kaboom":
// Kaboom
case "oops":
// Oops
default:
panic("Invalid kind")
}
}
import subprocess
# ...
@app.route('/run/<script>')
def run(script):
reply = subprocess.run(["python", script], stdout=subprocess.PIPE)
return reply.stdout