小编Sla*_*lam的帖子

如何在 Windows 上使用 python 让我的脚本每 30 分钟重复一次

我有下面的脚本,我希望它每 30 分钟运行一次,有人能给我指出正确的方向吗?

我已经搜索了这样的现有问题,但似乎没有找到任何适合我的脚本的想法,但不知道这是否是我愚蠢。

我的脚本点击屏幕上的不同位置,然后进行屏幕截图,然后将图像发送到我的 Gmail 帐户。

import pyautogui
import time
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email import encoders
import os


time.sleep(5)
pyautogui.PAUSE = 1
pyautogui.moveTo(922,134)
pyautogui.click()
pyautogui.PAUSE = 1
pyautogui.moveTo(178,277)
pyautogui.click()
pyautogui.PAUSE = 1
pyautogui.moveTo(178,297)
pyautogui.click()
pyautogui.PAUSE = 1
pyautogui.moveTo(178,315)
pyautogui.click()
pyautogui.PAUSE = 1
pyautogui.screenshot('web.png')

pyautogui.PAUSE = 5

gmail_user = "user@gmail.com"
gmail_pwd = "password"

to = "user@gmail.com"
subject = "Report"
text = "Picture report"
attach = 'web.png'

msg = …
Run Code Online (Sandbox Code Playgroud)

python time automation python-3.x

5
推荐指数
2
解决办法
9747
查看次数

如何获取elasticsearch文档中每个单词的总数?

我搜索了这个问题,但找不到任何有用的答案.我想获得文档中每个单词的总计数,例如我的索引中有一些推文,并且有一条推文上写着这样的话:"这里很无聊,我想去我家甜蜜的家".查询应该返回如下响应:

It:1
is:1
so:1
boring:1
here:1
I:1
want:1
to:2
go:1
my:1
home:2
sweet:1
Run Code Online (Sandbox Code Playgroud)

有可能吗?

elasticsearch

4
推荐指数
1
解决办法
4728
查看次数

Python 相当于将 POST 负载用单引号括起来

与 Splunk 相比,这更像是一个 Python 问题,但如果有人这样做的话将会很有帮助......特别是在这里,有一个关于在单个 POST 中向服务器发送多个指标的讨论。他们提供的示例是使用curl 并将整个有效负载用单引号(\')括起来,例如

\n\n
curl -k http://<IP address or host name or load balancer name>:8088/services/collector  \\\n-H "Authorization: Splunk 98a1e071-bc35-410b-8642-78ce7d829083"                         \n\\\n-d \'{"time": 1505501013.000,"source":"disk","host":"host_99","fields": \n{"region":"us-west-1","datacenter":"us-west- 1a","rack":"63","os":"Ubuntu16.10","arch":"x64","team":"LON","service":"6","service_version":"0","service_environment":"test","path":"/dev/sda1","fstype":"ext3","_value":999311222774,"metric_name":"total"}}\n{"time": 1505511013.000,"source":"disk","host":"host_99","fields": \n{"region":"us-west-1","datacenter":"us-west-1a","rack":"63","os":"Ubuntu16.10","arch":"x64","team":"LON","service":"6","service_version":"0","service_environment":"test","path":"/dev/sda1","fstype":"ext3","_value":1099511627776,"metric_name":"total"}}\'\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的问题是如何在 python \xe2\x80\x93 中执行相同的操作,即您不能像在curl命令中那样将多个JSON对象用单引号括起来 - 这只会使整个有效负载成为字符串。是否有其他包装可以用于此目的?

\n\n

所以,这有效:

\n\n
payload = {"time": 1505501013.000,"source":"disk","host":"host_99","fields": \n{"region":"us-west-1","datacenter":"us-west- 1a","rack":"63","os":"Ubuntu16.10","arch":"x64","team":"LON","service":"6","service_version":"0","service_environment":"test","path":"/dev/sda1","fstype":"ext3","_value":999311222774,"metric_name":"total"}}\n
Run Code Online (Sandbox Code Playgroud)\n\n

但这并不:

\n\n
payload = {"time": 1505501013.000,"source":"disk","host":"host_99","fields": \n{"region":"us-west-1","datacenter":"us-west- 1a","rack":"63","os":"Ubuntu16.10","arch":"x64","team":"LON","service":"6","service_version":"0","service_environment":"test","path":"/dev/sda1","fstype":"ext3","_value":999311222774,"metric_name":"total"}}\n {"time": 1505511013.000,"source":"disk","host":"host_99","fields": \n{"region":"us-west-1","datacenter":"us-west-1a","rack":"63","os":"Ubuntu16.10","arch":"x64","team":"LON","service":"6","service_version":"0","service_environment":"test","path":"/dev/sda1","fstype":"ext3","_value":1099511627776,"metric_name":"total"}}\n
Run Code Online (Sandbox Code Playgroud)\n\n

仅供参考,那么 POST 看起来像:

\n\n
 resp = requests.post(splunkurl,json=payload,headers=headers)\n
Run Code Online (Sandbox Code Playgroud)\n

python json splunk

2
推荐指数
1
解决办法
532
查看次数

如何以〜C速度排空异步发电机?

目前我正在使用 async for _ in asyncgen(): pass

我正在寻找“快速路由”实现,用于同步生成器的方法是:

deque(maxlen=0).extend(generator)
Run Code Online (Sandbox Code Playgroud)

python generator async-await python-asyncio

1
推荐指数
1
解决办法
107
查看次数