首页 > 解决方案 > 在 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()

标签: pythondeploymentopenshift

解决方案


在终端上使用以下命令

  1. oc 登录 -u 管理员

登录openshift集群后创建新项目

  1. oc 新项目 python

在项目python中创建应用程序

  1. oc new-app python~ https:// 你的应用程序所在的存储库 url --name myapp

获取创建的 pod 的状态

  1. 状态

暴露 pod 的服务

  1. oc 暴露 svc/myapp

推荐阅读