This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Continuous Integration and Delivery | |
on: [push] | |
env: | |
# | |
DJANGO_TUTORIAL_API_IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')/store | |
DJANGO_TUTORIAL_NGINX_IMAGE: ghcr.io/$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')/nginx | |
REGISTRY: ghcr.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from pydantic import BaseModel, ValidationError | |
from ajit_utils import list_of_dict_to_json | |
# Define the Pydantic data class (model) | |
class Person(BaseModel): | |
name: str | |
age: int | |
city: str = "Unknown" # Default value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def list_of_dict_to_json(list_data_dict:list, filename:str)-> None: | |
"""This is a utiltiy method to write python dictonary data | |
to a json file. | |
Args: | |
list_data_dict (list): Python list of dict having the data | |
filename (str): Filename for the json file | |
example_data = [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id": 1, | |
"title": "Python Programming for Beginners", | |
"author": "John Smith", | |
"price": 29.99 | |
}, | |
{ | |
"id": 2, | |
"title": "JavaScript: The Good Parts", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"title": "Example Book 1", | |
"author": "John Doe", | |
"isbn": "1234567890123", | |
"pages": 350, | |
"language": "English" | |
}, | |
{ | |
"title": "Example Book 2", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"spidername": "Quote Ajit Source", | |
"start_urls": ["https://quotes-scrape.netlify.app/"], | |
"quote_div_main": "div.quote-container", | |
"title_selector": "h2.title", | |
"author_selector": "p.author" | |
}, | |
{ | |
"spidername": "Brainy Quote", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from jinja2 import Environment, FileSystemLoader | |
from urllib.parse import urlparse | |
import os | |
# Load JSON configuration | |
with open('sources.json') as f: | |
sources = json.load(f) | |
# Set up Jinja2 environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scrapy | |
from spiders_automation_demo.items import QuoteItem | |
from spiders_automation_demo.itemsloader import QuoteLoader | |
class {{ spiderclass}}(scrapy.Spider): | |
name = "{{spidername}}" | |
allowed_domains = ["{{allowed_domains}}"] | |
start_urls = {{start_urls}} | |
def parse(self, response): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ITEM_PIPELINES = { | |
'spiders_automation_demo.pipelines.FilterQuotesPipelineLoveOrLife': 300, | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scrapy.exceptions import DropItem | |
class FilterQuotesPipelineLoveOrLife: | |
def process_item(self, item, spider): | |
# Check if 'love' or 'life' is in the text | |
if 'love' in item['title'].lower() or 'life' in item['title'].lower(): | |
return item | |
else: | |
raise DropItem(f"Quote without 'love' or 'life' in title text: {item['title']}") |
NewerOlder