-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqotd.py
More file actions
64 lines (54 loc) · 1.48 KB
/
Copy pathqotd.py
File metadata and controls
64 lines (54 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
import xows
import asyncio
import requests
import socket
import random
from time import sleep
# set your username and passwword here for WebEx device login
USERNAME=""
PASSWORD=""
DEVICEIP=""
#
# this uses pubic RFC QOTD servers
#
def rfcqotd():
QOTDSERVERS = ["djxmmx.net", "alpha.mike-r.com"]
server = random.choice(QOTDSERVERS)
serveraddr = (server, 17)
q = socket.create_connection(serveraddr)
quote = q.recv(4096)
q.close()
return (quote.decode("utf-8"))
#
# this uses a rest API to quote-garden.herokuapp.com
# example: https://quote-garden.herokuapp.com/api/v3/quotes/random
# as of 12/6/21 there are 72672 pages
#
def restqotd():
BASEURL="https://quote-garden.herokuapp.com/api/v3/quotes/random"
try:
response = requests.get(BASEURL)
jsonResponse = response.json()
data = jsonResponse["data"]
quote = data[0]["quoteText"]
author = data[0]["quoteAuthor"]
str = (author+":"+quote)
if len(str) > 128:
# try not to overwhelm the quote server
sleep(10)
# recurse until we get a quote that is <= 128 characters
return(restqotd())
else:
return (str)
except requests.ConnectionError as error:
return("Quote server unavailable")
#
#
#
async def update(quote):
async with xows.XoWSClient(DEVICEIP, username=USERNAME, password=PASSWORD) as deskpro:
await deskpro.xSet(['Configuration', 'UserInterface', 'CustomMessage'], quote)
quote = restqotd()
#quote = rfcqotd()
asyncio.run(update(quote))