Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
twitter2pg
Advanced tools
Richard Wen
rrwen.dev@gmail.com
Module for extracting Twitter data to PostgreSQL databases.
npm
npm install --save twitter2pg
For the latest developer version, see Developer Install.
The usage examples show how to get Twitter data into a PostgreSQL table named twitter_data
with a tweets
jsonb column:
row | tweets |
---|---|
1 | {...} |
2 | {...} |
3 | {...} |
... | ... |
Create an appropriate PostgreSQL table with psql before running the usage examples:
-h
: host address-p
: port number-d
: database name-U
: user name with table creation permissions-c
: PostgreSQL querypsql -h localhost -p 5432 -d postgres -U postgres -c "CREATE TABLE twitter_data(tweets jsonb);"
twitter
using a GET requeststatuses
twitter_data
tweets
column in the twitter_data
table contains one tweetvar twitter2pg = require('twitter2pg');
options = {
pg: {},
twitter: {},
jsonata: 'statuses' // filter tweets for statuses array only
};
// (options_twitter) Twitter API options
options.twitter = {
method: 'get', // get, post, delete, or stream
path: 'search/tweets', // api path
params: {q: 'twitter'} // query tweets
};
// (options_twitter_connection) Twitter API connection keys
options.twitter.connection = {
consumer_key: '***', // default: process.env.TWITTER_CONSUMER_KEY
consumer_secret: '***', // default: process.env.TWITTER_CONSUMER_SECRET
access_token_key: '***', // default: process.env.TWITTER_ACCESS_TOKEN_KEY
access_token_secret: '***' // default: process.env.TWITTER_ACCESS_TOKEN_SECRET
};
// (options_pg) PostgreSQL options
// In query, $1 are the JSON tweets
options.pg = {
table: 'twitter_data',
column: 'tweets',
query: 'INSERT INTO $options.pg.table($options.pg.column) SELECT * FROM json_array_elements($1);'
};
// (options_pg_connection) PostgreSQL connection details
options.pg.connection = {
host: 'localhost', // default: process.env.PGHOST
port: 5432, // default: process.env.PGPORT
database: 'postgres', // default: process.env.PGDATABASE
user: 'postgres', // default: process.env.PGUSER
password: '***' // default: process.env.PGPASSWORD
};
// (twitter2pg_rest) Query tweets using REST API into PostgreSQL table
twitter2pg(options).catch(err => {
console.error(err.message);
});
twitter
twitter_data
tweets
column of the twitter_data
tablevar twitter2pg = require('twitter2pg');
options = {};
// (options_twitter) Twitter API options
options.twitter = {
method: 'stream', // get, post, delete, or stream
path: 'statuses/filter',// api path
params: {track: 'twitter'} // track tweets
};
// (options_twitter_connection) Twitter API connection keys
options.twitter.connection = {
consumer_key: '***', // default: process.env.TWITTER_CONSUMER_KEY
consumer_secret: '***', // default: process.env.TWITTER_CONSUMER_SECRET
access_token_key: '***', // default: process.env.TWITTER_ACCESS_TOKEN_KEY
access_token_secret: '***' // default: process.env.TWITTER_ACCESS_TOKEN_SECRET
};
// (options_pg) PostgreSQL options
// In query, $1 are the JSON tweets
options.pg = {
table: 'twitter_data',
column: 'tweets',
query: 'INSERT INTO $options.pg.table($options.pg.column) VALUES($1);'
};
// (options_pg_connection) PostgreSQL connection details
options.pg.connection = {
host: 'localhost', // default: process.env.PGHOST
port: 5432, // default: process.env.PGPORT
database: 'postgres', // default: process.env.PGDATABASE
user: 'postgres', // default: process.env.PGUSER
password: '***' // default: process.env.PGPASSWORD
};
// (twitter2pg_stream) Stream tweets into PostgreSQL table
var stream = twitter2pg(options);
stream.on('error', function(error) {
console.error(error.message);
});
See Documentation for more details.
Reports for issues and suggestions can be made using the issue submission interface.
When possible, ensure that your submission is:
Code contributions are submitted via pull requests:
A template of the code contribution explanation is provided below:
## Purpose
The purpose can mention goals that include fixes to bugs, addition of features, and other improvements, etc.
## Description
The description is a short summary of the changes made such as improved speeds or features, and implementation details.
## Changes
The changes are a list of general edits made to the files and their respective components.
* `file_path1`:
* `function_module_etc`: changed loop to map
* `function_module_etc`: changed variable value
* `file_path2`:
* `function_module_etc`: changed loop to map
* `function_module_etc`: changed variable value
## Notes
The notes provide any additional text that do not fit into the above sections.
For more information, see Developer Install and Implementation.
Install the latest developer version with npm
from github:
npm install git+https://github.com/rrwen/twitter2pg
Install from git
cloned source:
npm
git clone https://github.com/rrwen/twitter2pg
cd twitter2pg
npm install
git clone https://github.com/rrwen/twitter2pg
cd twitter2pg
.env
file (see tests/README.md)npm install
npm test
Use documentationjs to generate html documentation in the docs
folder:
npm run docs
See JSDoc style for formatting syntax.
twitter2pg
folder, add all files and commit changesgit add .
git commit -a -m "Generic update"
git push
package.json
npm test
npm run docs
npm login
npm publish
The module twitter2pg uses the following npm packages for its implementation:
npm | Purpose |
---|---|
twitter2return | Connections to the Twitter API REST and Streaming Application Programming Interfaces (APIs) using twitter with a query language called jsonata to filter TWitter JSON data before inserting into PostgreSQL |
pg | Insert Twitter data Connect to PostgreSQL tables |
twitter2return <-- Extract Twitter data from API and Filter JSON data
|
pg <-- Insert filtered Twitter data into PostgreSQL table
FAQs
Module for extracting Twitter data to PostgreSQL databases
The npm package twitter2pg receives a total of 0 weekly downloads. As such, twitter2pg popularity was classified as not popular.
We found that twitter2pg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.