Skip to content

Commit

Permalink
Merge pull request #231 from peterspr/json-example-file
Browse files Browse the repository at this point in the history
docs: created json example
  • Loading branch information
d-Rickyy-b authored Jun 7, 2023
2 parents 245d75e + c8b5808 commit 1663362
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
### Added
- Implemented a JSON file save example ([031cecd](https://github.com/d-Rickyy-b/pastepwn/pull/231/commits/031cecdb19631673b03069b8ddc20ce5ed113c36))
### Changed

## [2.1.0] - 2023-04-01
Expand Down
39 changes: 39 additions & 0 deletions examples/json_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-

import logging.handlers
import pathlib

from pastepwn import PastePwn
from pastepwn.actions import SaveJSONAction
from pastepwn.analyzers import GoogleApiKeyAnalyzer

# Setting up the logging to a file in ./logs/
logdir_path = pathlib.Path(__file__).parent.joinpath("logs").absolute()
logfile_path = logdir_path.joinpath("pastepwn.log")

# Creates ./logs/ if it doesn't exist
if not logdir_path.exists():
logdir_path.mkdir()

logfile_handler = logging.handlers.WatchedFileHandler(logfile_path, "a", "utf-8")

logger = logging.getLogger(__name__)
logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO, handlers=[logfile_handler, logging.StreamHandler()])

# A database can be provided to store pastes. This example does not implement a database.
pastepwn = PastePwn()

# PastePWN has 3 components: Scraper, Analyzer, Action.
# This example implements the default Scraper, Google API Key Analyzer, and JSON File Save Action.
# Generic Action to save Pastes to JSON File.
json_path = "./json_pastes"
save_json_action = SaveJSONAction(json_path)

# Google API Key Analyzer with save JSON action.
google_api_key_analyzer = GoogleApiKeyAnalyzer(save_json_action)

# Add the analyzer to the pastepwn instance.
pastepwn.add_analyzer(google_api_key_analyzer)

# Start scraping/saving.
pastepwn.start()

0 comments on commit 1663362

Please sign in to comment.