Skip to content

Instantly share code, notes, and snippets.

@MrShameer
Last active October 28, 2022 09:26
Show Gist options
  • Save MrShameer/133a23bcf6e06de3922d076c68dacbbd to your computer and use it in GitHub Desktop.
Save MrShameer/133a23bcf6e06de3922d076c68dacbbd to your computer and use it in GitHub Desktop.
A script to give random jokes in maya
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
@MrShameer
Copy link
Author

For more info on the joke generated, you can check our Joke API

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment