Last active
October 28, 2022 09:26
-
-
Save MrShameer/133a23bcf6e06de3922d076c68dacbbd to your computer and use it in GitHub Desktop.
A script to give random jokes in maya
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide2 import QtWidgets | |
import sys | |
from urllib import urlencode | |
import urllib2 | |
import json | |
class UI(QtWidgets.QMessageBox): | |
def __init__(self, *args, **kwargs): | |
super(UI, self).__init__(*args, **kwargs) | |
self.setWindowTitle("Joke By Shameer (The Joke is not mine)") | |
self.setStandardButtons(QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Retry) | |
data = { | |
'type': 'single', | |
} | |
joke = self.http_post("https://v2.jokeapi.dev/joke/Any?", data) | |
joke = json.loads(joke) | |
self.setText(joke['joke']) | |
def http_post(self, url, data): | |
post = urlencode(data) | |
req = urllib2.Request(url+post) | |
response = urllib2.urlopen(req) | |
return response.read() | |
App = QtWidgets.QApplication.instance() | |
if App is None: | |
App = QtWidgets.QApplication(sys.argv) | |
while True: | |
window = UI().exec_() | |
if window == QtWidgets.QMessageBox.Ok: | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For more info on the joke generated, you can check our Joke API