abstarction package

Submodules

abstarction.SocMetricParser module

class abstarction.SocMetricParser.SocMetricParserAbstraction(header: dict, db_session: dict[sqlalchemy.orm.Session], soc_type: int)[source]

Bases: ABC

Abstraction for social network parsers.

add_post(post_object: Posts, post_metrics_object: PostMetrics, db_session: sqlalchemy.orm.Session) None[source]

a common method for all parsers that adds posts and post metrics to the database.

Parameters
  • header (dict) – steady header value

  • db_session (dict) – dictionary of specified sql alchemy sessions

  • soc_type (int) – type of social network specified in SocTypes enum

add_relevant_posts(res_id, item_id, url, text, likes, comment, date, db_session: sqlalchemy.orm.Session, reposts=0) None[source]

A common method for all parsers that adds posts and post metrics to the database via add_post method and updates metric collection date.

Parameters
  • res_id (int) – resource id received from database

  • item_id (dict) – item id received from social network API

  • url (str) – url of resource

  • text (str) – content of post

  • likes (int) – number of post likes received from social network API

  • comment (int) – number of comments likes received from social network API

  • date (string) – date then post was created

  • db_session (Session) – session taken from list of sql alchemy session

  • reposts (int) – number of reposts likes received from social network API

get_resources_up_to_date() list[tuple][source]

method of obtaining resources for at least the last hour :return: list of resources that was updated more than an hour ago

abstract parse_profile_metrics() None[source]

An abstract method responsible for different method of parsing profile metrics via social services api

abstract parse_profile_posts(item: dict) None[source]

An abstract method responsible for different method of parsing posts metrics via social services api

Parameters

item (dict) – single post from posts list

abstract run() None[source]

method for running the parser

send_statistic_to_telegram()[source]

The method that the tg_logger module uses to send a message to the telegram bot

abstract set_proxy() None[source]

An abstract method responsible for passing to self.proxy a dictionary with a link to an authenticated proxy server.

telegram_logger_init(token, user_list)[source]

Method using tg_logger module to create logger attribute

Parameters
  • token (str) – api token of telegram bot

  • user_list (int) – list of user chat ids

update_resources_dates(res_id: int) None[source]

method which updates metric collection date

Parameters

header (dict) – steady header value

Module contents

class abstarction.SocMetricParserAbstraction(header: dict, db_session: dict[sqlalchemy.orm.Session], soc_type: int)[source]

Bases: ABC

Abstraction for social network parsers.

add_post(post_object: Posts, post_metrics_object: PostMetrics, db_session: sqlalchemy.orm.Session) None[source]

a common method for all parsers that adds posts and post metrics to the database.

Parameters
  • header (dict) – steady header value

  • db_session (dict) – dictionary of specified sql alchemy sessions

  • soc_type (int) – type of social network specified in SocTypes enum

add_relevant_posts(res_id, item_id, url, text, likes, comment, date, db_session: sqlalchemy.orm.Session, reposts=0) None[source]

A common method for all parsers that adds posts and post metrics to the database via add_post method and updates metric collection date.

Parameters
  • res_id (int) – resource id received from database

  • item_id (dict) – item id received from social network API

  • url (str) – url of resource

  • text (str) – content of post

  • likes (int) – number of post likes received from social network API

  • comment (int) – number of comments likes received from social network API

  • date (string) – date then post was created

  • db_session (Session) – session taken from list of sql alchemy session

  • reposts (int) – number of reposts likes received from social network API

get_resources_up_to_date() list[tuple][source]

method of obtaining resources for at least the last hour :return: list of resources that was updated more than an hour ago

abstract parse_profile_metrics() None[source]

An abstract method responsible for different method of parsing profile metrics via social services api

abstract parse_profile_posts(item: dict) None[source]

An abstract method responsible for different method of parsing posts metrics via social services api

Parameters

item (dict) – single post from posts list

abstract run() None[source]

method for running the parser

send_statistic_to_telegram()[source]

The method that the tg_logger module uses to send a message to the telegram bot

abstract set_proxy() None[source]

An abstract method responsible for passing to self.proxy a dictionary with a link to an authenticated proxy server.

telegram_logger_init(token, user_list)[source]

Method using tg_logger module to create logger attribute

Parameters
  • token (str) – api token of telegram bot

  • user_list (int) – list of user chat ids

update_resources_dates(res_id: int) None[source]

method which updates metric collection date

Parameters

header (dict) – steady header value