Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Embed Tweets
{
"cells": [
{
"metadata": {
"ExecuteTime": {
"end_time": "2021-09-08T18:12:49.625000+09:00",
"start_time": "2021-09-08T09:12:49.624Z"
}
},
"id": "bc1f33af",
"cell_type": "markdown",
"source": "# Jupyter Notebook にツイートを埋め込む\n\nJulia の Jupyter notebook にツイートを埋め込む方法\n\n- https://github.com/jupyter/notebook/issues/2790\n\nの議論を参考にしている."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2021-09-08T18:24:53.087000+09:00",
"start_time": "2021-09-08T09:24:52.387Z"
},
"trusted": true
},
"id": "41b0ba6d",
"cell_type": "code",
"source": "using HTTP\nusing JSON",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2021-09-08T18:24:53.365000+09:00",
"start_time": "2021-09-08T09:24:52.388Z"
},
"scrolled": true,
"trusted": false
},
"id": "a9f2af94",
"cell_type": "code",
"source": "\"\"\"\n display_tweet(link)\n\nDisplay tweet `link` on Jupyter Notebook using [Twitter's oEmbed API](https://dev.twitter.com/web/embedded-tweets)\nSee: [jupyter/notebook/issues/2790](https://github.com/jupyter/notebook/issues/2790) for more detail\n\n`link` can be taken from `Copy link to Tweet`\n\"\"\"\nfunction display_tweet(link)\n api = \"https://publish.twitter.com/oembed?url=$link\"\n r = response = HTTP.request(\"GET\", api);\n j = JSON.parse(String(r.body))\n HTML(j[\"html\"])\nend\n",
"execution_count": 2,
"outputs": [
{
"data": {
"text/plain": "display_tweet"
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2021-09-08T18:20:39.698000+09:00",
"start_time": "2021-09-08T09:20:39.627Z"
}
},
"id": "ef3c4809",
"cell_type": "markdown",
"source": "# 使い方\n\n- 埋め込みたいつぶやきのリンクを取得. `Copy link to Tweet` から得ることができる. ここでは Makie チームの呟きを埋め込んでみよう."
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2021-09-08T18:24:56.756000+09:00",
"start_time": "2021-09-08T09:24:52.389Z"
},
"trusted": false
},
"id": "c4e84e97",
"cell_type": "code",
"source": "display_tweet(\"https://twitter.com/MakiePlots/status/1431949586181074946?s=20\")",
"execution_count": 3,
"outputs": [
{
"data": {
"text/html": "<blockquote class=\"twitter-tweet\"><p lang=\"en\" dir=\"ltr\">Julius Krumbiegel has put a ton of work into redesigning the Makie docs, check them out: <a href=\"https://t.co/ciktFzd378\">https://t.co/ciktFzd378</a> <br>Also, Makie almost got 1000 stars, anyone wants to help get there? :) <a href=\"https://t.co/5uAJr4WoG0\">https://t.co/5uAJr4WoG0</a></p>&mdash; Makie (@MakiePlots) <a href=\"https://twitter.com/MakiePlots/status/1431949586181074946?ref_src=twsrc%5Etfw\">August 29, 2021</a></blockquote>\n<script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n",
"text/plain": "HTML{String}(\"<blockquote class=\\\"twitter-tweet\\\"><p lang=\\\"en\\\" dir=\\\"ltr\\\">Julius Krumbiegel has put a ton of work into redesigning the Makie docs, check them out: <a href=\\\"https://t.co/ciktFzd378\\\">https://t.co/ciktFzd378</a> <br>Also, Makie almost got 1000 stars, anyone wants to help get there? :) <a href=\\\"https://t.co/5uAJr4WoG0\\\">https://t.co/5uAJr4WoG0</a></p>&mdash; Makie (@MakiePlots) <a href=\\\"https://twitter.com/MakiePlots/status/1431949586181074946?ref_src=twsrc%5Etfw\\\">August 29, 2021</a></blockquote>\\n<script async src=\\\"https://platform.twitter.com/widgets.js\\\" charset=\\\"utf-8\\\"></script>\\n\")"
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
]
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"gist": {
"id": "",
"data": {
"description": "Embed Tweets",
"public": true
}
},
"kernelspec": {
"name": "julia-sys-1.6",
"display_name": "Julia-sys 1.6.2",
"language": "julia"
},
"language_info": {
"file_extension": ".jl",
"name": "julia",
"mimetype": "application/julia",
"version": "1.6.2"
},
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"base_numbering": 1,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"varInspector": {
"window_display": false,
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"library": "var_list.py",
"delete_cmd_prefix": "del ",
"delete_cmd_postfix": "",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"library": "var_list.r",
"delete_cmd_prefix": "rm(",
"delete_cmd_postfix": ") ",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
]
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment