Skip to content

Commit

Permalink
fix twitter followers count bug (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Amnah199 authored Jul 17, 2024
1 parent 0d0e2a8 commit 31201ae
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions collector/src/collector/cli/twitter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
import re
import time

from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions

import click
from datadog import initialize
from datadog import api as dd
from datadog import initialize
from selenium import webdriver
from selenium.webdriver.chrome.options import Options as ChromeOptions


@click.group("twitter")
Expand Down Expand Up @@ -35,7 +34,7 @@ def twitter_scraper(ctx, username, dd_api_key, dd_api_host, dry_run):

try:
follower_count_element_idx = response.find('<a href="/Haystack_AI/verified_followers"')
ctx.obj["FOLLOWERS"] = find_next_match(response, follower_count_element_idx, r'>\d{3,}<')[1:-1]
ctx.obj["FOLLOWERS"] = find_next_match(response, follower_count_element_idx, r'>[\d,]+<')[1:-1]
except:
ctx.obj["FOLLOWERS"] = 0

Expand All @@ -48,6 +47,8 @@ def twitter_scraper(ctx, username, dd_api_key, dd_api_host, dry_run):
@click.pass_context
def followers(ctx):
followers = ctx.obj.get('FOLLOWERS')
if followers:
followers = followers.replace(',', '')
if not ctx.obj.get('DRY_RUN'):
dd.Metric.send(
metric="haystack.twitter.followers",
Expand Down

0 comments on commit 31201ae

Please sign in to comment.