Query string: Difference between revisions

Content deleted Content added
m Reverted edits by 51.36.51.18 (talk) (HG) (3.4.13)
Tags: Reverted Mobile edit Mobile web edit
Line 67:
Some [[Character (computing)|characters]] cannot be part of a URL (for example, the space) and some other characters have a special meaning in a URL: for example, the character <code>#</code> can be used to further specify a subsection (or [[Fragment identifier|fragment]]) of a document. In HTML forms, the character <code>=</code> is used to separate a name from a value. The URI generic syntax uses [[Percent-encoding#Percent-encoding reserved characters|URL encoding]] to deal with this problem, while HTML forms make some additional substitutions rather than applying percent encoding for all such characters. SPACE is encoded as '<code>+</code>' or "<code>%20</code>".<ref name="w3schools" />
 
[[HTML import random
[[HTML 5]] specifies the following transformation for submitting HTML forms with the "GET" method to a web server. The following is a brief summary of the algorithm:
from telegram import Update
* Characters that cannot be converted to the correct charset are replaced with HTML [[numeric character reference]]s<ref name="html5 urlencoded" />
from telegram.ext import Updater, CommandHandler, CallbackContext
* SPACE is encoded as '<code>+</code>' or '<code>%20</code>'
* Letters (<code>A</code>–<code>Z</code> and <code>a</code>–<code>z</code>), numbers (<code>0</code>–<code>9</code>) and the characters '<code>~</code>','<code>-</code>','<code>.</code>' and '<code>_</code>' are left as-is
* <code>+</code> is encoded by %2B
* All other characters are encoded as a <code>%HH</code> [[hexadecimal]] representation with any non-ASCII characters first encoded as UTF-8 (or other specified encoding)
 
# Replace this with your actual token
The octet corresponding to the tilde ("<code>~</code>") is permitted in query strings by RFC3986 but required to be percent-encoded in HTML forms to "<code>%7E</code>".
TOKEN = "7320690023:AAFD3jjjJ9jbcFjwOz5JqoJOEW9_EVhgwmI"
 
# Start command handler
The encoding of SPACE as '<code>+</code>' and the selection of "as-is" characters distinguishes this encoding from RFC 3986.
def start(update: Update, context: CallbackContext) -> None:
update.message.reply_text('Welcome to the 91 Club Color Prediction Bot! Use /predict to get the next color prediction.')
 
# Help command handler
def help(update: Update, context: CallbackContext) -> None:
update.message.reply_text('Use /predict to get a color prediction for the 91 Club game.')
 
# Color prediction handler
def predict(update: Update, context: CallbackContext) -> None:
# Randomly select a color (You can change this logic to something else)
colors = ['Red', 'Green', 'Blue']
prediction = random.choice(colors)
update.message.reply_text(f"The predicted color for the next 91 Club game is: {prediction}")
 
# Create the Updater and pass it your bot’s token.
def main():
updater = Updater(TOKEN)
dispatcher = updater.dispatcher
 
# Register the command handlers
dispatcher.add_handler(CommandHandler('start', start))
dispatcher.add_handler(CommandHandler('help', help))
dispatcher.add_handler(CommandHandler('predict', predict))
 
# Start the Bot
updater.start_polling()
updater.idle()
 
if __name__ == '__main__':
main()
 
== Example ==