track the number of followers of a twitter account

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

track the number of followers of a twitter account

Post by papoo »

this script allows you to follow any twitter account, not necessarily yours

Code: Select all

--[[ twitterFollowers.lua for [ domoticzVents >= 2.4 ]
    
author/auteur = papoo
update/mise à jour = 10/01/2019
creation = 10/01/2019
https://pon.fr/dzvents-suivre-le-nombre-dabonnes-dun-compte-twitter
https://github.com/papo-o/domoticz_scripts/blob/master/dzVents/scripts/twitterFollowers.lua
https://easydomoticz.com/forum/viewtopic.php?f=17&t=7809
--]]
--------------------------------------------
------------ Variables à éditer ------------
--------------------------------------------
local twitterName = 'pap_oo'
local deviceTwitter = '@pap_oo'         -- nom (entre ' ') ou idx du custom device twitter, nil si non utilisé
local intervalleMiseAJourEnMinutes = 30   -- intervalle de mise à jour du script.
--------------------------------------------
----------- Fin variables à éditer ---------
--------------------------------------------
local nomScript = 'nombre de Followers sur twitter'
local versionScript = '1.0'

return {
    active = true,
    on      =     
                {   timer           =   { 'every '..tostring(intervalleMiseAJourEnMinutes)..' minutes',},
                    httpResponses   =   { nomScript }    -- Trigger the handle Json part
                },

  logging =   { level    =   domoticz.LOG_INFO,
                marker = nomScript..' '..versionScript
               },

    
    execute = function(domoticz, reponse)

        local twitter_API_url  = 'https://cdn.syndication.twimg.com/widgets/followbutton/info.json?screen_names='..twitterName  -- url


        if (reponse.isTimer) then
            domoticz.openURL({
                url = twitter_API_url,
                callback = nomScript
            })

        end
        if (reponse.isHTTPResponse and reponse.ok) then
            if (reponse.data) then
               reponse.data = string.gsub (reponse.data, '%[', "")
               reponse.data = string.gsub (reponse.data, '%]', "")
               json = domoticz.utils.fromJSON(reponse.data)
               domoticz.log(tostring(json.name)..' à '..tostring(json.followers_count)..' followers sur twitter sous le pseudo de '..tostring(json.screen_name),domoticz.LOG_INFO)
               if json.followers_count and deviceTwitter then
                    domoticz.devices(deviceTwitter).updateCustomSensor(tonumber(json.followers_count))
               end
            end
   
        end
    end   
}

Attachments
2019-01-10 14_36_58-Domoticz.png
2019-01-10 14_36_58-Domoticz.png (7.47 KiB) Viewed 540 times
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest