steam-review-scraper / main.py
main.py
Raw
import argparse
import logging
import os
import sys
import time

from steam_review_scraper import steam, common, db_common


def main():
    # Try to open settings to verify they are valid json.
    common.get_settings()

    db_common.create_database()

    apps = common.get_settings().get_tracked_apps()
    appids = [app.appid for app in apps]

    compare_time = int(time.time())

    logging.info("Parsing reviews for: {0}".format(appids))
    for appid in appids:
        steam.parse_reviews_for_app(appid)
        steam.remove_deleted_reviews(appid, compare_time)


if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="""
            Retrieves and parses Steam reviews for the tracked games set in the settings file.
            Can put the parsed data in the DB or in a .csv file"""
    )
    parser.add_argument(
        "-s",
        "--silent",
        action="store_true",
        help="If set, only errors will be printed during the retrieve and parse process"
    )
    options = parser.parse_args()

    log_level = "INFO"
    if options.silent:
        log_level = "ERROR"
    common.init_logging("steam-review-scraper.log", log_level)

    if not os.path.exists("output"):
        os.makedirs("output")

    start_time = time.time()
    main()

    logging.info("Done, total time elapsed: {0}".format(
        common.pretty_time(time.time() - start_time)))