简体   繁体   中英

Deploy a simple python bot on Openshift

This is a very simple pure python app (not Django or Flask).

What is the step-by-step and correct way of deploying this app on Openshift ? , so that it runs forever.

Code:

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()

use following on commands on terminal

  1. oc login -u admin

After login in openshift cluster create new project

  1. oc new-project python

Create an application in project python

  1. oc new-app python~ https:// repository url where your application is located --name myapp

get the status of created pod

  1. oc status

expose the service of pod

  1. oc expose svc/myapp

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM