Instantly share code, notes, and snippets.
Created
March 5, 2019 06:33
-
Star
1
(1)
You must be signed in to star a gist -
Fork
0
(0)
You must be signed in to fork a gist
-
Save nikhilkumarsingh/286f13410df9a969e446853119b85a49 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import requests" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"url = \"https://ide.geeksforgeeks.org/main.php\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"code = \"\"\"\n", | |
"#include<stdio.h>\n", | |
"\n", | |
"int main() {\n", | |
" printf(\"hello\");\n", | |
" return 0;\n", | |
"}\n", | |
"\"\"\"" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"data = {\n", | |
" 'lang': 'c',\n", | |
" 'code': code,\n", | |
" 'input': '',\n", | |
" 'save': True\n", | |
"}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"r = requests.post(url, data=data)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'valid': '1',\n", | |
" 'time': '0',\n", | |
" 'compResult': 'S',\n", | |
" 'output': 'hello',\n", | |
" 'rntError': '',\n", | |
" 'cmpError': '',\n", | |
" 'id': 'bHr1xtD0JV',\n", | |
" 'memory': '1.4079074859619',\n", | |
" 'lxcOutput': '',\n", | |
" 'hash': '4dc607bbc68c89c1d7fef0207fb8fb3b_Tester_U16'}" | |
] | |
}, | |
"execution_count": 10, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"r.json()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"## cURL to Python requests\n", | |
"https://curl.trillworks.com/" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import requests\n", | |
"\n", | |
"headers = {\n", | |
" 'cookie': '_ga=GA1.2.1976496781.1511868474; geeksforgeeks_consent_status=dismiss; __utmc=245605906; __utma=245605906.1976496781.1511868474.1551590114.1551763565.147; __utmz=245605906.1551763565.147.130.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided); _gid=GA1.2.1624225676.1551765473; __utmb=245605906.4.10.1551763565',\n", | |
" 'origin': 'https://ide.geeksforgeeks.org',\n", | |
" 'accept-encoding': 'gzip, deflate, br',\n", | |
" 'accept-language': 'en-IN,en-GB;q=0.9,en-US;q=0.8,en;q=0.7',\n", | |
" 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36',\n", | |
" 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8',\n", | |
" 'accept': 'application/json, text/javascript, */*; q=0.01',\n", | |
" 'referer': 'https://ide.geeksforgeeks.org/CsRQ97RJ5K',\n", | |
" 'authority': 'ide.geeksforgeeks.org',\n", | |
" 'x-requested-with': 'XMLHttpRequest',\n", | |
"}\n", | |
"\n", | |
"data = {\n", | |
" 'lang': 'C',\n", | |
" 'code': '#include <stdio.h>\\n\\nint main() {\\n\\t//code\\n\\treturn 0;\\n}',\n", | |
" 'input': 'ffkdgnke',\n", | |
" 'save': 'false'\n", | |
"}\n", | |
"\n", | |
"response = requests.post('https://ide.geeksforgeeks.org/main.php', headers=headers, data=data)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'valid': '1',\n", | |
" 'time': '0',\n", | |
" 'compResult': 'S',\n", | |
" 'output': '',\n", | |
" 'rntError': '',\n", | |
" 'cmpError': '',\n", | |
" 'id': '',\n", | |
" 'memory': '1.2203245162964',\n", | |
" 'lxcOutput': '',\n", | |
" 'hash': 'fd9ee3d1fb3e7ecaab4169c3f7908c96_Tester_U16'}" | |
] | |
}, | |
"execution_count": 13, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"response.json()" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment