Блог пользователя purplesyringa

Автор purplesyringa, история, 3 года назад, перевод, По-русски

Привет, Codeforces!

Я на днях написал скрипт, который публикует все новые посты (и их обновления) с Codeforces в Телеграм-канал -- с форматированием и всем причитающимся.

Обновления должны приходить достаточно быстро, меньше чем за 5 минут.

Приятного использования!

  • Проголосовать: нравится
  • +63
  • Проголосовать: не нравится

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Автокомментарий: текст был обновлен пользователем purplesyringa (предыдущая версия, новая версия, сравнить).

»
3 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Автокомментарий: текст был обновлен пользователем purplesyringa (предыдущая версия, новая версия, сравнить).

»
3 года назад, # |
  Проголосовать: нравится +13 Проголосовать: не нравится

Did you literally made it in 5 minutes?

»
3 года назад, # |
  Проголосовать: нравится +8 Проголосовать: не нравится

How does it work? Can you share the code? As codeforces doesn't have rss/atom feed, it is a really good initiative. Thanks.

  • »
    »
    3 года назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    It parses 'Recent actions' in the sidebar and parses these posts. Then it checks if these posts are new and posts them to Telegram if so. There are some hacks to make Codeforces formatting look better, the rest is rather simple. I'm not sure if I want to share the code because if many people used it, it would increase load on Codeforces servers. You can DM me if you need it.

    • »
      »
      »
      3 года назад, # ^ |
        Проголосовать: нравится +11 Проголосовать: не нравится

      You could've used more reliable API for recent actions (see https://codeforces.com/apiHelp/methods#recentActions) instead of parsing HTML which can change at any moment.

      • »
        »
        »
        »
        3 года назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        I know about the API and I don't like it. First, it has too low limits to be any useful. Second, the API doesn't return blog content so I'd still have to resort to manual parsing.

        • »
          »
          »
          »
          »
          3 года назад, # ^ |
          Rev. 2   Проголосовать: нравится +5 Проголосовать: не нравится

          Codeforces API allows 5 requests per second — should be more than enough to load data once and send to all users.

          The API also does return blog content, you have to:
          1. Request recentActions
          2. Request full versions of BlogEntries by IDs from RecentActions using blogEntry.view

          This is fully up to you, of course, it's your bot :)

          • »
            »
            »
            »
            »
            »
            3 года назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится

            There are limits other than per second limits. In my experience, even rate limiting API like that doesn't help, you still get 'forbidden' or whatever the error was--I don't remember--if you make many requests per hour.

            Also, I'm not just talking about RPS metric. Some APIs that return lists/arrays don't return more than a few hundreds of records.

          • »
            »
            »
            »
            »
            »
            3 года назад, # ^ |
              Проголосовать: нравится 0 Проголосовать: не нравится
            1. Request full versions of BlogEntries by IDs from RecentActions using blogEntry.view

            That API doesn't return post content.

»
3 года назад, # |
  Проголосовать: нравится +11 Проголосовать: не нравится

Hi purplesyringa I have a version of the new cf logo in a slightly higher resolution for the profile picture of the channel: link