Exemplo n.º 1
0
def _load_hashtag_data(tags: list):
    """Scrape hashtag data for the given hashtags"""
    hashtag_objs = []
    with tqdm.tqdm(total=len(tags), position=0) as progress:
        for tag in tags:
            time.sleep(abs(np.random.normal(3, 2)))
            hashtag = Hashtag.from_hashtag(tag)
            hashtag.static_load()
            hashtag_objs.append({
                "hashtag": tag,
                "posts": hashtag.amount_of_posts,
                "datetime": datetime.datetime.now()
            })
            progress.update(1)
    return hashtag_objs
Exemplo n.º 2
0
    def test_from_hashtag(self, page_instance):
        expected_hashtag = "kotlin"
        result_profile: Hashtag = Hashtag.from_hashtag(hashtag=expected_hashtag)

        assert result_profile.url == page_instance.url
Exemplo n.º 3
0
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

sys.path.insert(0, os.path.abspath(".."))
from instascrape import Hashtag

# We will start by running a loop and scraping data at random intervals until the predefined timeframe has elapsed.

# In[2]:

# Metadata
TOTAL_TIME = 60  # Total time
WAIT_TIME = 5  # Mean wait time for random normal distribution
photography = Hashtag.from_hashtag("photography")
instagram = Hashtag.from_hashtag("instagram")

# Create a list of tuples containing data scraped at random
# intervals during the time period
current_time = datetime.datetime.now()
end_time = current_time + datetime.timedelta(seconds=TOTAL_TIME)
photography_data = []
instagram_data = []
while current_time < end_time:
    # Wait for  normally randomized amount of time
    rand_time = abs(np.random.normal(WAIT_TIME, 1.5))
    time.sleep(WAIT_TIME)

    # Scrape data and append to respective lists
    photography.static_load()
Exemplo n.º 4
0
def test_from_hashtag(kotlin_hashtag):
    result_hashtag: Hashtag = Hashtag.from_hashtag(hashtag=kotlin_hashtag.name)
    result_hashtag.static_load()

    assert result_hashtag.url == kotlin_hashtag.url
    assert result_hashtag.name == kotlin_hashtag.name
Exemplo n.º 5
0
def test_from_hashtag(kotlin_hashtag):
    result_hashtag: Hashtag = Hashtag.from_hashtag(hashtag=kotlin_hashtag.name)

    assert result_hashtag.url == kotlin_hashtag.url