Skip to content

Instantly share code, notes, and snippets.

@hsj51
Last active April 3, 2021 12:28
Show Gist options
  • Save hsj51/36fdd59ebe47d77be6ecd70c66b84683 to your computer and use it in GitHub Desktop.
Save hsj51/36fdd59ebe47d77be6ecd70c66b84683 to your computer and use it in GitHub Desktop.
Colab Notebook to generate credentials.json and/or telegra.ph token & to generate/download SAs, add them to team drive or to upload then to GitHub.
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "aria-telegram-mirror-bot.ipynb",
"provenance": [],
"collapsed_sections": [],
"authorship_tag": "ABX9TyM0EvxbEq1DRE7RmqkJ3iya",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/hsj51/36fdd59ebe47d77be6ecd70c66b84683/old-aria-telegram-mirror-bot.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"metadata": {
"id": "w1JpfE5dj3t3",
"cellView": "form"
},
"source": [
"#@title #<b>👈🏻 Run this cell after filling the form\n",
"\n",
"#@markdown ## <b>Generate `credentials.json`\n",
"\n",
"#@markdown * Follow Step 2 of [heroku_guide](https://github.com/arghyac35/aria-telegram-mirror-bot/blob/master/heroku_guide.md#pre-requisites-not-to-be-followed-while-using-service-account-skip-to-deployment) to get `client_secret.json`.\n",
"\n",
"#@markdown * Paste its code below\n",
"code = \"\" #@param {type:\"string\"}\n",
"\n",
"#@markdown <b>Or\n",
"\n",
"#@markdown * If you have alredy created a github gist/direct link for client_secret.json, enter its url\n",
"url = \"\" #@param {type:\"string\"}\n",
"\n",
"#@markdown ## <b>Generate `TELEGRAPH_TOKEN`\n",
"\n",
"#@markdown Not sure, see `TELEGRAPH_TOKEN` in [Constants Description](https://github.com/arghyac35/aria-telegram-mirror-bot#constants-description) section.\n",
"\n",
"#@markdown * Tick below checkbox to generate Telegraph token\n",
"gen_telegraph_token = False #@param {type:\"boolean\"}\n",
"\n",
"#@markdown * Account name for telegra.ph account.\n",
"account_name =\"MirrorBot\" #@param {type:\"string\"}\n",
"\n",
"#@markdown #<b> Now run this cell to generate `credentials.json` and/or `telegra.ph token`.\n",
"\n",
"#@markdown If you have any issues regarding this notebook, contact me using Telegram: [@hsj51](https://t.me/hsj51)\n",
"\n",
"\n",
"from google.colab import files\n",
"import subprocess, IPython, urllib.request, os, sys\n",
"\n",
"def prep():\n",
" !apt install nodejs;\n",
" !git clone https://github.com/arghyac35/aria-telegram-mirror-bot bot;cd bot; npm install;\n",
"\n",
"def credential():\n",
" cmd=!cd bot; npm run generateDriveCredentials;\n",
" if os.path.isfile('/content/bot/credentials.json'): pass\n",
" else:\n",
" output(cmd)\n",
" print('Something went wrong, credentials.json not generated')\n",
" sys.stdout.flush()\n",
" os._exit(0)\n",
"\n",
"def post():\n",
" upload = subprocess.check_output(\"curl --upload-file /content/bot/credentials.json https://transfer.sh/credentials.json\", shell=True).decode().split(\"transfer.sh\")\n",
" download_link = \"transfer.sh/get\".join(upload)\n",
" style_code = \\\n",
"'''\n",
"<style>\n",
".pure-material-button-contained{margin:50px;top:10%;display:inline-block;box-sizing:border-box;border:none;border-radius:4px;padding:0 16px;min-width:64px;height:36px;vertical-align:middle;text-align:center;text-overflow:ellipsis;text-transform:uppercase;color:rgb(var(--pure-material-onprimary-rgb,255,255,255));background-color:rgb(var(--pure-material-primary-rgb,33,150,243));box-shadow:0 3px 1px -2px rgba(0,0,0,.2),0 2px 2px 0 rgba(0,0,0,.14),0 1px 5px 0 rgba(0,0,0,.12);font-family:var(--pure-material-font, \"Roboto\", \"Segoe UI\", BlinkMacSystemFont, system-ui, -apple-system);font-size:14px;font-weight:500;line-height:36px;overflow:hidden;outline:0;cursor:pointer;transition:box-shadow .2s}.pure-material-button-contained::-moz-focus-inner{border:none}.pure-material-button-contained::before{content:\"\";position:absolute;top:0;bottom:0;left:0;right:0;background-color:rgb(var(--pure-material-onprimary-rgb,255,255,255));opacity:0;transition:opacity .2s}.pure-material-button-contained::after{content:\"\";position:absolute;left:50%;top:50%;border-radius:50%;padding:50%;width:32px;height:32px;background-color:rgb(var(--pure-material-onprimary-rgb,255,255,255));opacity:0;transform:translate(-50%,-50%) scale(1);transition:opacity 1s,transform .5s}.pure-material-button-contained:focus,.pure-material-button-contained:hover{box-shadow:0 2px 4px -1px rgba(0,0,0,.2),0 4px 5px 0 rgba(0,0,0,.14),0 1px 10px 0 rgba(0,0,0,.12)}.pure-material-button-contained:hover::before{opacity:.08}.pure-material-button-contained:focus::before{opacity:.24}.pure-material-button-contained:hover:focus::before{opacity:.3}.pure-material-button-contained:active{box-shadow:0 5px 5px -3px rgba(0,0,0,.2),0 8px 10px 1px rgba(0,0,0,.14),0 3px 14px 2px rgba(0,0,0,.12)}.pure-material-button-contained:active::after{opacity:.32;transform:translate(-50%,-50%) scale(0);transition:transform 0s}.pure-material-button-contained:disabled{color:rgba(var(--pure-material-onsurface-rgb,0,0,0),.38);background-color:rgba(var(--pure-material-onsurface-rgb,0,0,0),.12);box-shadow:none;cursor:initial}.pure-material-button-contained:disabled::before{opacity:0}.pure-material-button-contained:disabled::after{opacity:0}\n",
"</style>\n",
"'''\n",
" html_code = \\\n",
"'''\n",
"<center><button class=\"pure-material-button-contained\" onclick=\" window.open('{download_link}','_blank')\">Click here to Download your credentials.json</button></center>\n",
"'''\n",
" files.download('/content/bot/credentials.json')\n",
" display(IPython.display.HTML(style_code))\n",
" display(IPython.display.HTML(eval('f'+repr(html_code))))\n",
"\n",
"def output(cmd):\n",
" for i in cmd: print(i)\n",
"\n",
"if url:\n",
" prep()\n",
" urllib.request.urlretrieve(url,'/content/bot/client_secret.json')\n",
" credential()\n",
" post()\n",
"elif code:\n",
" prep()\n",
" with open(\"/content/bot/client_secret.json\",\"w\") as client_secret:\n",
" client_secret.write(code)\n",
" credential()\n",
" post()\n",
"else:\n",
" print(\"Not generating credentials.json.\")\n",
"\n",
"if gen_telegraph_token:\n",
" prep()\n",
" !cd bot; echo \"$account_name\" | npm run generateTelegraphToken\n",
"else:\n",
" print(\"Not generating telegra.ph token.\")"
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment