Git Product home page Git Product logo

webscrap-to-social's Introduction

Description

A simple NestJS tool to scrap text and image from any website and post that content in your twitter account.

Installation

$ npm install

Configuration

Configure Twitter Account

Create a .env file in your root directory, and add the following variables (without <> sympols and quotes). You can get these keys by creating a developer account in twitter.

TWITTER_CONSUMER_KEY=<YOUR_TWITTER_CONSUMER_KEY>
TWITTER_CONSUMER_SECRET=<YOUR_TWITTER_CONSUMER_SECRET>
TWITTER_ACCESS_TOKEN=<YOUR_TWITTER_ACCESS_TOKEN>
TWITTER_ACCESS_TOKEN_SECRET=<YOUR_TWITTER_ACCESS_TOKEN_SECRET>

Web Scrap Configuration

In the src/config.ts, change the webScrapInfo object with your targeting websites.

Properties Values Type Description
url 'http://samplewebsite.com' string Website url to scrap the data
query ['.container p', 'main .headline'] Array List of query to search the DOM.
imageQuery '.container img' string Query to scrap the image.
imageOptions {imageBaseUrl etc.. } object several image options like cropping etc. More info in the below table
limit 280 number Text limit of the post. especially for twitter.
tags ['#motivation','#success'] Array Tags to append in the post

Image Options

In the imageOptions object, there are several properties to modify.

Properties Values Type Description
imageBaseUrl 'http://samplewebsite.com/photos' string Base url for the image scraping.
imageAttr 'src' string Attribute of the image element. by default it's src, if you want to select anyother attribute you can change this property.
crop true boolean To enable crop functionality.
cropOptions { x: 0, y: 0, width: 1200, height: 580 } object Crop Options.

Sample Web Config

export const webScrabConfig = {
    'webname1': {
        url: 'https://www.sample.com/some-page',
        query: ['.qotd-h-short a.b-qt', '.qotd-h-short a.bq-aut'],
        imageQuery: '.Qt .p-qotd',
        imageOptions: {
            imageBaseUrl: 'https://www.sample.com',
            imageAttr: 'src',
            crop: true,
            cropOptions: {
                x: 0,
                y: 0,
                width: 1200,
                height: 560
            }
        },
        limit: 280,
        tags: ["#quotes", "#quotesoftheday", "#motivation", "#motivationalquotes", "#books", "#booklovers", "#bookstagram", "#quotestoliveby", "#fitness", "#life", "#lifequotes"]
    },
    webname2: {
        url: 'https://www.sample.com/some-page',
        query: ['.qotd-h-short a.b-qt', '.qotd-h-short a.bq-aut'],
        imageQuery: '.Qt .p-qotd',
        imageOptions: {
            imageBaseUrl: 'https://www.sample.com',
            imageAttr: 'src',
            crop: true,
            cropOptions: {
                x: 0,
                y: 0,
                width: 1200,
                height: 560
            }
        },
        limit: 280,
        tags: ["#quotes", "#quotesoftheday", "#motivation", "#motivationalquotes", "#books", "#booklovers", "#bookstagram", "#quotestoliveby", "#fitness", "#life", "#lifequotes"]
    } 

}

API ENDPOINTS TO SCRAP AND TWEET

1. /post-text-tweet?webConfig=webname

This end point will scrap the text using the config you provided (website url and query array) and post the text content in your twitter account.

2. /post-imageonly-tweet?webConfig=webname

It's used to scrap the image from the website (imageBaseUrl and imageQuery) and post it in your twitter account.

3. /post-image-tweet?webConfig=webname

It'll post both the text and image which is created on the fly with sample backgrounds and scraped text. (This Endpoint won't scrap the image from website, instead it create a image with a sample background in assets/images/samples folder and scraped text on it).

All the above end points have a webConfig query param to select a particular web-scrapping configuration based on the property name.

NOTE

This tool is still under development, currently it supports Twitter. Soon, it'll support FB Page API.

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

webscrap-to-social's People

Contributors

bearnithi avatar

Stargazers

Rahul A R avatar  avatar

Watchers

 avatar

Forkers

ajjp

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.