Package: telegram-updates-tweets
Telegram Updates TweetsThis package monitors the number of participants in a telegram channel and can post gains/losses updates to twitter.
It requires a twitter API key and telegram API key.InstallationUse the package managerpipto install telegram_updates_tweets.Simple versionpipinstalltelegram_updates_tweetsWith monitoring and database loggingpipinstalltelegram_updates_tweets[logging,monitoring]UsageThe package is configured with a bunch of options. It also supports environmental variabls (see docker instructions below for details).Simple version (powershell)python-mtelegram_updates_tweets--tweet-losses100`--twitter-keyOopNaGdhsdhgsgRg0FVAOzC`--twitter-secretVWyvs87IKYsgsdhdswgg23g3g3gPbcETEV8HlvmnCx`--twitter-access-token134062562626437-1zh50lhr3dggsgsg8oYGrSh3eW`--twitter-access-token-secret5jGpCn79ZexhcQafaf43yt3gNEKWQVzzU`--telegram-api-id20161454`--telegram-api-hashb7dae636835151536egwgf6ffc69`--telegram-channel-nameCHANNELNAME`--tweet-loss-template'Der Kanal hat {loss_step} Leser verloren und ist jetzt bei {count}'`--tweet-graph-template'24h Bericht, aktuelle Anzahl der Leser ist {count}, Änderung {total_change:+d} Leser'Logging/monitoring version (powershell)python-mtelegram_updates_tweets--tweet-losses100`--twitter-keyOopNaGdhsdhgsgRg0FVAOzC`--twitter-secretVWyvs87IKYsgsdhdswgg23g3g3gPbcETEV8HlvmnCx`--twitter-access-token134062562626437-1zh50lhr3dggsgsg8oYGrSh3eW`--twitter-access-token-secret5jGpCn79ZexhcQafaf43yt3gNEKWQVzzU`--telegram-api-id20161454`--telegram-api-hashb7dae636835151536egwgf6ffc69`--mongodb127.0.0.1:27017--telegram-channel-nameCHANNELNAME`--tweet-loss-template'Der Kanal hat {loss_step} Leser verloren und ist jetzt bei {count}'`--tweet-graph-template'24h Bericht, aktuelle Anzahl der Leser ist {count}, Änderung {total_change:+d} Leser'`--tweet-graph20`--tweet-graph-img-template'Innerhalb der letzten {hours} Std.: {total_change:+d} Leser'`--monitoring-port3134--monitoring-password'sgwjth23iut2tkjakd'Template variables--tweet-loss-templateand--tweet-gain-template{loss_step}is the--tweet-lossesparameter{gain_step}is the--tweet-gainsparameter{count}is the current number of participants in the channel{channel_name}is the channel name as defined by--telegram-channel-name--tweet-graph-img-templateis the title in the image of the 24h report image{hours}is the rounded number between the oldest and the newest datapoint in the database (typically integer 24){total_change:+d}is the count of the oldest datapoint minus the count of the newest,+dadd an explicit plus sign to positive numbersDocker imageThe application can be pulled withdockerpulljcq9kw2s/telegram_updates_tweets:latestEnv FileTo configure the application within the docker image I recommend using a.envfile.
The variable names have a prefixTT_and are the uppercase versions with underscores of the options described below.Example for.envwith logging and monitoring:TT_TWEET_LOSSES=100
TT_TWITTER_KEY=g3g3g3gwegwgfejhegweg
TT_TWITTER_SECRET=sjgpjpiowgjij0u030t32jgjpjwjijjoijygyupsjfjsofjofjo
TT_TWITTER_ACCESS_TOKEN=162162615161515-1515kjk1j5h12hjlk1b1g54
TT_TWITTER_ACCESS_TOKEN_SECRET=5mklmjijafkshfishifhaohfhhg3f23fih2
TT_TELEGRAM_API_ID=515661515
TT_TELEGRAM_API_HASH=15414141414ef1fffafffdf14
TT_MONGODB=host.docker.internal:27017
TT_TELEGRAM_CHANNEL_NAME=CHANNELNAME
TT_TWEET_LOSS_TEMPLATE=Der Kanal hat {loss_step} Leser verloren und ist jetzt bei {count} #hashtag
TT_TWEET_GRAPH_TEMPLATE=24h Bericht, aktuelle Anzahl der Leser ist {count}, Änderung {total_change:+d} Leser @someacc #hashtab
TT_TWEET_GRAPH=20
TT_TWEET_GRAPH_IMG_TEMPLATE=Innerhalb der letzten {hours} Std.: {total_change:+d} Leser
TT_MONITORING_PORT=12345
TT_MONITORING_PASSWORD=256n52jj512b412b1Running docker imageI recommend running the python module in terminal first to get the session of telegram and mount it into the container, thesession-journalfile should not need to be mounted.Powershelldockerrun--namett-v"$pwd/anon.session:/app/anon.session"--network="host"--env-file.env-p12345:12345-itjcq9kw2s/telegram_updates_tweets:latestFor developmentdockerstoptt;dockerrmtt;dockerrun--namett-v"$pwd/anon.session:/app/anon.session"--network="host"--env-file.env-p12345:12345-itjcq9kw2s/telegram_updates_tweets:latestOptionsUsage: python -m telegram_updates_tweets [OPTIONS]

  Connects to telegram as a user and checks every 60minutes the subscriber
  count of the given channel. It allows to tweet gains and/or losses with
  additional info.

Options:
  --tweet-gains INTEGER           Deactivated if <=0, otherwise describes the
                                  step. Example: 100 -> tweet at 1900, 2000,
                                  2100, ...

  --tweet-losses INTEGER          Deactivated if <=0, otherwise describes the
                                  step. Example: 100 -> tweet at 2100, 2000,
                                  1900, ...

  --tweet-loss-template TEXT      This template will be formatted and posted
                                  on loss

  --tweet-gain-template TEXT      This template will be formatted and posted
                                  on gain

  --tweet-graph INTEGER           Deactivated if <0, otherwise 0..23 specifies
                                  the time when to post a 24h summary graph
                                  (requires mongodb)

  --tweet-graph-template TEXT     This template will be formatted and posted
                                  if --tweet-graph is specified

  --tweet-graph-img-template TEXT
                                  This template will be formatted and used in
                                  the image if --tweet-graph is specified

  --monitoring-port INTEGER       Deactivated if <=0, otherwise 0..65000
                                  specifies the port which allows to fetch
                                  monitoring information. Requires
                                  --monitoring-password

  --monitoring-password TEXT      Is required if --monitoring-port is set. Is
                                  used in basic authentication password,
                                  username can be any.

  --check-frequency INTEGER       Check period in seconds
  --twitter-key TEXT              Also called API key, is created by the
                                  twitter app

  --twitter-secret TEXT           The secret of the twitter app
  --twitter-access-token TEXT     The access token of the oauth procedure
  --twitter-access-token-secret TEXT
                                  The secret of the oauth access token
  --telegram-api-id INTEGER       The number created by telegram
  --telegram-api-hash TEXT        The api hash created by telegram
  --telegram-channel-name TEXT    The name of the channel of interest
  --mongodb TEXT                  IP:PORT of the mongo db, if not set, no data
                                  will be logged

  --help                          Show this message and exit.MonitoringIf you want to have downtime alerts via email, I recommend using a Google Cloud Service.Start your application with--monitoring-portand--monitoring-passwordGo toOperations>Monitoring>Uptime ChecksCreate Uptime CheckTargetProtocol: HTTPResource Type: URLHostname: your-server-url.host.comPath:/Check Frequency: 15minMore Options:Regions: GlobalHost Header: emptyPort: as set in--monitoring-portEncrypt custom headers: uncheckedAuthentication, Username:userAuthentication, Password: as set in--monitoring-passwordResponse ValidationResponse Timeout: 10sContent matching is enabled: checkedResponse Content Match Type:ContainsResponse Content:OKLog Check Failures: checkedAlert and Notification
Create an email notification channelDevelopmentAfter cloning this repo executegit config core.hooksPath hooksin the root directory.Install poetryhttps://python-poetry.org/docs/poetry config settings.virtualenvs.in-project truepoetry installpoetry shellAPI keysTo use this package a twitter API key and a telegram API key are needed, these keys will be used to request OAUTH tokens from one twitter account and a telegram account.Create a twitter APP with 'write' permissionhttps://developer.twitter.com/en/portal/projects-and-appsthis creates the--twitter-keyand the--twitter-secretthe application will print aauthorization link, open it, give permission to your own app the use your twitter profileit will print the--twitter-access-tokenand--twitter-access-token-secretall subsequent calls should use all four parametersCreate a telegram APP as described inhttps://core.telegram.org/api/obtaining_api_idthis generates a--telegram-api-id(numbers) and--telegram-api-hash(string)when the application is started with this parameters, it will ask for your phone number, you will receive a code from telegram, enter it in the applicationthis will create a token file called 'anon.session' and 'anon.session-journal'all subsequent calls should not prompt for other infoContributingPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.Please make sure to update tests as appropriate.LicenseMIT