from flask import Flask, render_template
from flask_pymongo import PyMongo
from pymongo import MongoClient
import os
import random
app = Flask(__name__)
client = MongoClient('mongodb', 27017)
db = client.test
def add_many():
db.images.insert_many([
{'id': 1, 'title': "https://firebasestorage.googleapis.com/v0/b/docker-curriculum.appspot.com/o/catnip%2F0.gif?alt=media&token=0fff4b31-b3d8-44fb-be39-723f040e57fb"},
{'id': 2, 'title': "https://firebasestorage.googleapis.com/v0/b/docker-curriculum.appspot.com/o/catnip%2F1.gif?alt=media&token=2328c855-572f-4a10-af8c-23a6e1db574c"},
{'id': 3, 'title': "https://firebasestorage.googleapis.com/v0/b/docker-curriculum.appspot.com/o/catnip%2F10.gif?alt=media&token=647fd422-c8d1-4879-af3e-fea695da79b2"},
{'id': 4, 'title': "https://firebasestorage.googleapis.com/v0/b/docker-curriculum.appspot.com/o/catnip%2F11.gif?alt=media&token=900cce1f-55c0-4e02-80c6-ee587d1e9b6e"},
{'id': 5, 'title': "https://firebasestorage.googleapis.com/v0/b/docker-curriculum.appspot.com/o/catnip%2F2.gif?alt=media&token=8a108bd4-8dfc-4dbc-9b8c-0db0e626f65b"},
{'id': 6, 'title': "https://firebasestorage.googleapis.com/v0/b/docker-curriculum.appspot.com/o/catnip%2F3.gif?alt=media&token=4e270d85-0be3-4048-99bd-696ece8070ea"},
{'id': 7, 'title': "https://firebasestorage.googleapis.com/v0/b/docker-curriculum.appspot.com/o/catnip%2F4.gif?alt=media&token=e7daf297-e615-4dfc-aa19-bee959204774"},
{'id': 8, 'title': "https://firebasestorage.googleapis.com/v0/b/docker-curriculum.appspot.com/o/catnip%2F5.gif?alt=media&token=a8e472e6-94da-45f9-aab8-d51ec499e5ed"},
{'id': 9, 'title': "https://firebasestorage.googleapis.com/v0/b/docker-curriculum.appspot.com/o/catnip%2F7.gif?alt=media&token=9e449089-9f94-4002-a92a-3e44c6bd18a9"},
{'id': 10, 'title': "https://firebasestorage.googleapis.com/v0/b/docker-curriculum.appspot.com/o/catnip%2F8.gif?alt=media&token=80a48714-7aaa-45fa-a36b-a7653dc3292b"},
{'id': 11, 'title': "https://firebasestorage.googleapis.com/v0/b/docker-curriculum.appspot.com/o/catnip%2F9.gif?alt=media&token=a57a1c71-a8af-4170-8fee-bfe11809f0b3"},
])
@app.route("/cats/<int:image_id>")
def index(image_id):
result = db.images.find_one({"id": image_id})
if result:
return render_template("index.html", url=result["title"])
else:
return "Не найдено"
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)), debug=True)
import sys
from PyQt5.QtCore import QEventLoop, QUrl
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from bs4 import BeautifulSoup
class Render(QWebEngineView):
def __init__(self):
self.html = None
self.app = QApplication(sys.argv)
QWebEngineView.__init__(self)
self.loadFinished.connect(self._loadFinished)
def _callable(self, data):
self.html = data
def _loadFinished(self, result):
self.page().toHtml(self._callable)
def get_data(self, url):
self.html = None
self.load(QUrl(url))
while self.html is None:
self.app.processEvents(QEventLoop.ExcludeUserInputEvents |
QEventLoop.ExcludeSocketNotifiers |
QEventLoop.WaitForMoreEvents)
return self.html
if __name__ == '__main__':
print("Collecting data...")
render = Render()
for p in range(3):
html = render.get_data(f'https://hh.ru/search/vacancy?area=&fromSearchLine=true&st=searchVacancy&text=&page={p}')
# get data from page
bs4 = BeautifulSoup(html, "lxml")
for elem in bs4.find_all("div", "vacancy-serp-item"):
print(elem.find('a', 'bloko-link').text)
import valve.source.a2s
SERVER_ADDRESS = (..., ...)
with valve.source.a2s.ServerQuerier(SERVER_ADDRESS) as server:
info = server.info()
players = server.players()
print("{player_count}/{max_players} {server_name}".format(**info))
for player in sorted(players["players"], key=lambda p: p["score"], reverse=True):
print("{score} {name}".format(**player))
>>> import a2s
>>> address = ("stomping.kinofnemu.net", 27015)
>>> a2s.info(address)
SourceInfo(protocol=17, server_name=" 24/7 Dustbowl :: Nemu's Stomping Ground", map_name='cp_dustbowl',
folder='tf', game='Team Fortress', app_id=440, player_count=31, max_players=33, bot_count=21,
server_type='d', platform='l', password_protected=False, vac_enabled=True, version='5579073',
edf=177, port=27015, steam_id=85568392920040090, stv_port=None, stv_name=None,
keywords='brutus,celt,couch,cp,dustbowl,increased_maxplayers,nemu,nocrits,nodmgspread,pony,replays,vanilla',
game_id=440, ping=0.253798684978392)
>>> a2s.players(address)
[Player(index=0, name='Brutus', score=34, duration=836.4749145507812),
Player(index=0, name='RageQuit', score=6, duration=1080.8099365234375),
Player(index=0, name="Screamin' Eagles", score=1, duration=439.8598327636719)]
>>> a2s.rules(address)
{'coop': '0', 'deathmatch': '1', 'decalfrequency': '10', 'metamod_version': '1.10.7-devV',
'mp_allowNPCs': '1', 'mp_autocrosshair': '1', 'mp_autoteambalance': '0', 'mp_disable_respawn_times': '0',
'mp_fadetoblack': '0'}
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(int argc, char const* argv[]) {
char str[] = "soroto*11414*parapa*alfjjf*";
char* ptr = strchr(str, '*');
if (ptr) {
while (--ptr >= str) {
if (!isdigit(*ptr)) {
*ptr = '.';
}
}
}
puts(str);
return 0;
}
# Замените это:
rep_brain(ctx, member, 1)
# На это:
await rep_brain(ctx, member, 1)
#include <stdio.h>
void say_colour(char *s);
void say_colour(char *s){ printf("машина цветом %s",s);}
typedef struct { // Трейт
char z[10];
void(*say_colour)(char* s);
} Colour;
typedef struct {
char z[10];
void(*say_colour)(char *s);
int a; // Доп свойство
} Blue;
typedef struct{
Colour* colour;
} Car;
int main(int argc, char const *argv[]){
Blue b = {.z ="blue",.say_colour=say_colour};
Car car = {
.colour = (Colour*)&b // Преобразуем Blue в Colour
};
car.colour->say_colour("dsfd");
return 0;
}
from datetime import datetime
import requests
import asyncio
import aiohttp
LIST_ = ['Shishel','Mishel','Perdnul','Vishel',
'Papa','Mama',"Mila",'Ramu',
'Eniki','Beniki','Eli','Vareniki',
'Kreks','Feks','Peks','Keks']
accs = LIST_
counter_ = 0
start = datetime.now()
async def get_html(data):
url = f'http://httpbin.org/get?acc={data}'
try:
async with aiohttp.ClientSession() as session:
async with session.get(url) as r:
return (await r.json())['args']['acc']
except:
return 'failed'
async def acc():
global counter_, accs, start
counter_ += 1
one = accs.pop(0)
print(counter_, await get_html(one), len(accs))
accs.append( one )
if counter_ == len(accs):
counter_ = 0
end = datetime.now()
print('*' * 10, end - start, '*' * 10)
start = end
async def main():
tasks = []
while accs:
for _ in range(10): # Ограничение на 10 задач, которые выполняются одновременно
tasks.append(asyncio.get_event_loop().create_task(acc()))
await asyncio.wait(tasks) # Ожидание выполнения всех задач
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())
const { VK } = require('vk-io');