From anonymous, 1 Year ago, written in Ruby.
Embed
  1.  
  2. # ---- CONFIGURATION ----
  3.  
  4. # extra arguments for curl
  5. CURL_EXTRA_ARGS = "-s"
  6.  
  7. # extra CSS style to put before </head>
  8. EXTRA_STYLE = <<CSS
  9. .tgme_widget_message {
  10.   padding-top: 0.5em;
  11.   padding-bottom: 0.5em;
  12. }
  13. CSS
  14.  
  15. # maximum number of URLs passed to curl at one time
  16. MAX_URLS_PER_CALL = 16
  17.  
  18. # ---- END CONFIGURATION ----
  19.  
  20. # prints usage and calls exit().
  21. def usage!
  22.   script_name = File.basename(__FILE__)
  23.   STDERR.puts <<-USAGE
  24. Usage: ruby #{script_name} channel first_post_id last_post_id
  25.  
  26. Downloads posts from specified Telegram channel and writes them as a single,
  27. fancy HTML to standard output.
  28.  
  29. Example 1:
  30.   ruby #{script_name} nya_cats 100 150
  31.  
  32. Example 2:
  33.   ruby #{script_name} nya_cats 150 200 >posts.html && \\
  34.   firefox posts.html
  35.  
  36. It uses curl and https://t.me service.
  37.  
  38. Configuration is embedded into this script.
  39.  
  40.   USAGE
  41.   exit
  42. end
  43.  
  44. # parse args
  45. usage! if %W{-h, --help}.include? ARGV.first
  46. channel_name = ARGV[0] or usage!
  47. first_post_id = ARGV[1] or usage!
  48. last_post_id = ARGV[2] or usage!
  49.  
  50. # download all posts
  51. html = ""
  52. for post_ids in (first_post_id..last_post_id).each_slice(MAX_URLS_PER_CALL)
  53.   urls_arg =
  54.     post_ids.
  55.     map { |post_id| "https://t.me/#{channel_name}/#{post_id}?embed=1" }.
  56.     join(" ")
  57.   html << `curl #{CURL_EXTRA_ARGS} #{urls_arg}`
  58.   exit $?.exitstatus if $?.exitstatus != 0
  59. end
  60. # format and print
  61. html.gsub!(
  62.   /\s*\<script src=\"\/\/telegram\.org.*?\s*\<div class="tgme_widget_message" id="widget_message" id="widget_message"/m,
  63.  %(<div class="tgme_widget_message")
  64. )
  65. html.gsub!(
  66.  "<head>",
  67.  %(<head><base href="https://t.me">)
  68. )
  69. html.gsub!(
  70.  "</head>",
  71.  %(<style>#{EXTRA_STYLE}</style></head>)
  72. )
  73. print html
  74.  

Replies to download-telegram-channel rss

Title Name Language When
download-telegram-channel anonymous ruby 1 Year ago.