python - 在 Openshift 上部署一个简单的 Python 机器人
问题描述
这是一个非常简单的纯 python 应用程序(不是 Django 或 Flask)。
在Openshift上部署此应用程序的分步正确方法是什么?,使其永远运行。
代码:
import requests as rq
from bs4 import BeautifulSoup as bs
import time
url = "https://apod.nasa.gov/apod/astropix.html"
page = rq.get(url).content
soup = bs(page, 'html.parser')
response = soup.find('img')
if response == None:
imglink = soup.find('iframe')['src']
else:
imglink = 'https://apod.nasa.gov/apod/' + response['src']
def main():
while True:
sess = rq.Session()
cid='@*********'
turl = 'https://api.telegram.org/bot****************/'
if response == None:
imglink = soup.find('iframe')['src']
params = {'chat_id':cid,'text':imglink}
sess.post(turl + 'sendMessage', data=params)
else:
imglink = 'https://apod.nasa.gov/apod/' + response['src']
title = soup.find('b').get_text()
params = {'chat_id':cid,'photo':imglink,'caption':title}
sess.post(turl + 'sendPhoto', data=params)
time.sleep(30)
if __name__ == '__main__':
main()
解决方案
在终端上使用以下命令
- oc 登录 -u 管理员
登录openshift集群后创建新项目
- oc 新项目 python
在项目python中创建应用程序
- oc new-app python~ https:// 你的应用程序所在的存储库 url --name myapp
获取创建的 pod 的状态
- 状态
暴露 pod 的服务
- oc 暴露 svc/myapp
推荐阅读
- angular - 使用 *ngIf 根据属性显示元素
- python - 如何添加可变小时
- c++ - C++中的指针容器
- excel - 运行时错误 91 - 在用户窗体中测试代码时
- javascript - optionHTML 和 innerHTML 覆盖 `
- intellij-idea - 如何在整个文档中使用制表符缩进(PhpStorm)
- text - 我可以删除多 txt 文件中的换行符(回车)吗?
- c# - 将文件移动到子文件夹(每个子文件夹中有 n 个文件)
- python-3.x - 如何通过互联网(使用IP地址的分布式计算)将python ray用于独立计算机(每台计算机都有其用户名和密码)?
- sql - 如何根据日期字段查找客户第一个订单和后续订单的平均成本差异?