GVKun编程网logo

python计算codis中key分布在哪个slot中(codility python)

4

如果您想了解python计算codis中key分布在哪个slot中和codilitypython的知识,那么本篇文章将是您的不二之选。我们将深入剖析python计算codis中key分布在哪个slot

如果您想了解python计算codis中key分布在哪个slot中codility python的知识,那么本篇文章将是您的不二之选。我们将深入剖析python计算codis中key分布在哪个slot中的各个方面,并为您解答codility python的疑在这篇文章中,我们将为您介绍python计算codis中key分布在哪个slot中的相关知识,同时也会详细的解释codility python的运用方法,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

python计算codis中key分布在哪个slot中(codility python)

python计算codis中key分布在哪个slot中(codility python)

####使用python去计算key的crc32的值后和1024取余,就能得出key在codis的哪个slot中

  • 脚本如下 cat chslotid.py
#!/bin/env python

import binascii
import sys

try:
    print binascii.crc32(sys.argv[1])%1024
except Exception,e:
    print ''ERROR:%s'' %(e,)
    sys.exit(1)
  • 使用脚本

[root@ops5 ~]# python chslotid.py a

579

[root@ops5 ~]# python chslotid.py b

1017

Discord Bot Image Loop (Python)

Discord Bot Image Loop (Python)

如何解决Discord Bot Image Loop (Python)?

所以这个 discord Bot 是由三个 Python 脚本组成的。

main.py

GoodAnimeMemes.py

webserver.py

脚本说明:

webserver.py 脚本用于让我的 discord 机器人保持活动状态(24/7 运行)。

GoodAnimeMemes.py 脚本应该从网站上查找图像;在这种情况下,Reddit 并下载它们。

并且 main.py 脚本应该运行 GoodAnimeMemes.py 脚本以循环重新创建新图像,并通过我的 discord 服务器发送它们。

然而,这是我遇到的问题,不知道如何解决。

如何在每次循环结束时重新加载网页,而不使用 webdriver?

我使用的网站(Replit.com)不支持 webdrive 库。

我的代码有效。但分开。如果我运行 GoodAnimeMemes.py,它将根据网站最新的 5 张图片下载新图片。 如果我运行 main.py 它将发送我之前运行的图像。 但是,如果网站发布了新图片,它不会自动下载新图片,而是不断发送相同的图片... 为了这篇文章比较小,我把 main.py 做成只发一张图片。

有什么建议吗?

ma​​in.py

import os
import time
import discord
from discord.ext import commands
import GoodAnimeMemes
from webserver import keep_alive

bot = commands.Bot(command_prefix=''$'')

# Server info display in Console when bot runs
@bot.event
async def on_ready():
    guild_count = 0
    for guild in bot.guilds:
        print(f"- {guild.id} (name: {guild.name})")
        guild_count = guild_count + 1
    print("Bot is in " + str(guild_count) + " guilds.")

# Bot; when command is used,then bot starts
@bot.event
async def on_message(message):
    while message.content == "/start":
        # Obtain data
        exec(open("GoodAnimeMemes.py").read())

        # Send data 1
        print("! Downloading image...")
        await message.channel.send("hey dirtbag",file=discord.File("anime1.jpg"))
        print("Sent!")
        time.sleep(60)
        os.remove("anime1.jpg")
        # Pause bot for 4hrs (14400sec)
    else:
      pass


keep_alive()
TOKEN = os.environ[''disCORD_TOKEN'']
bot.run(TOKEN)

GoodAnimeMemes.py

import requests
from bs4 import BeautifulSoup
import time


headers = {''User-Agent'': xxxxxxxxxxxxxxxxxxxxxxxxxx}

url = "https://www.reddit.com/r/Animemes/"


r = requests.get(url,headers=headers)
# Check connection to website
if r.status_code == 200:
  print("Connected to website!")
  time.sleep(0.5)
elif r.status_code == 400:
  print("Page does not exist...")
  time.sleep(0.5)
elif r.status_code == 500:
  print("Unauthorized access!")
  time.sleep(0.5)
else:
  pass


soup = BeautifulSoup(r.text,''html.parser'')
# Print Title of Website
print(soup.title.text)
time.sleep(0.5)


links = soup.find_all("img",{"alt": "Post image"})
# Print How Many Links There Are
print("There are",len(links),"links to work with.")
time.sleep(0.8)


images = []
for link in links:
  if link.has_attr(''src''):
    # append individual URL to "images" list
    images.append(link[''src''])

# Set initial n value
n = 0

# Loop through list of URLs and download each with name "anime" + n
for image in images:
  n = n + 1
  with open ("anime" + str(n) + ''.jpg'',''wb'') as f:
    im = requests.get(image)
    f.write(im.content)

版权 (c) 2021,zumbynsr 保留所有权利。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

Docker 中的 Python Discord Bot

Docker 中的 Python Discord Bot

如何解决Docker 中的 Python Discord Bot?

我对 Docker 还很陌生,正在尝试在容器中安装一个 python discord 机器人。

我的项目文件夹结构如下:

- util
- - logger.py
- cogs
- - part-of-the-bot.py
- requirements.txt
- run.py

我查看了一些教程和 official python docker hub page 来帮助我创建 Dockerfile

FROM python:3.9

workdir /usr/src/app

copY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt

copY . .
RUN chmod +x run.py
 
CMD [ "python","run.py" ]

之后,我将 docker build -t bot . 和 docker-compose 与以下 YAML 文件一起使用:

version: ''3''

services: 
  discord-bot:
     image: bot:latest
     restart: unless-stopped
     volumes:
       - ~/volumes/bot:/usr/src/app

但是,它有一些问题: 目前我收到关于文件 /usr/src/app/run.py not existing 的错误:

python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory
python: can''t open file ''/usr/src/app/run.py'': [Errno 2] No such file or directory

我已经用 Dockerfile 中的一些 RUN pwdRUN ls 进行了检查,一切似乎都已正确复制。

我也无法确定是否需要为 discord 机器人打开一个端口才能工作。

编辑:我曾在 docker hub 上尝试过 discord.py 图像,但它似乎不适合 RaspBerry Pi 架构。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

OC 自定义 Model,使用 KVO,报错 this class is not key value coding-compliant for the key

OC 自定义 Model,使用 KVO,报错 this class is not key value coding-compliant for the key

OC 自定义 Model,使用 KVO,报错 this class is not key value coding-compliant for the key 

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not av...

pip is configured with locations that require TLS/SSL, however the ssl module in Python is not av...

解决办法:

brew update && brew upgrade
brew uninstall --ignore-dependencies openssl; brew install https://github.com/tebelorg/Tump/releases/download/v1.0.0/openssl.rb

本文分享 CNBlog - 削微寒的程序员之路。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

今天关于python计算codis中key分布在哪个slot中codility python的讲解已经结束,谢谢您的阅读,如果想了解更多关于Discord Bot Image Loop (Python)、Docker 中的 Python Discord Bot、OC 自定义 Model,使用 KVO,报错 this class is not key value coding-compliant for the key、pip is configured with locations that require TLS/SSL, however the ssl module in Python is not av...的相关知识,请在本站搜索。

本文标签: