Skip to content

Instantly share code, notes, and snippets.

View Niweera's full-sized avatar
🚁
________Apache_Helicopter_______

Nipuna Weerasekara Niweera

🚁
________Apache_Helicopter_______
View GitHub Profile
@Niweera
Niweera / xvfb.js
Last active February 27, 2022 04:25
XVFB to emulate a virtual display
import Xvfb from "xvfb";
const runHeadless = async () => {
const xvfb = new Xvfb();
xvfb.startSync();
// run the code that needs a
// virtual display
xvfb.stopSync();
@Niweera
Niweera / tweet-reply.js
Created February 26, 2022 19:45
Add a reply to the original tweet
import config from "../keys";
import { TwitterApi } from "twitter-api-v2";
const addReplyToTweet = async (tweetID, assetURL) => {
const twitterClient = new TwitterApi({
appKey: config.TWITTER_CONSUMER_KEY,
appSecret: config.TWITTER_CONSUMER_SECRET,
accessToken: config.TWITTER_ACCESS_TOKEN,
accessSecret: config.TWITTER_ACCESS_TOKEN_SECRET,
});
@Niweera
Niweera / mint-nft.js
Last active February 26, 2022 19:38
Mint the NFT on OpenSea
const mintNFT = async (browser, page) => {
const createButton = await page.$x('//button[contains(., "Create")]');
await createButton[0].click();
await page.waitForSelector(
"div.AssetSuccessModalContentreact__DivContainer-sc-1vt1rp8-1"
);
await page.waitForTimeout(10000);
const assetURL = page.url();
@Niweera
Niweera / add-metadata.js
Created February 26, 2022 19:11
Add metadata to the NFT
const fillLevels = async (page, tries) => {
const levelsButton = await page.$x(
'//*[@id="main"]/div/div/section/div[2]/form/section/div[2]/div/div[2]/button'
);
await levelsButton[0].click();
await page.waitForSelector('input[placeholder="Speed"]');
await page.focus('input[placeholder="Speed"]');
await page.keyboard.type("Tries", { delay: 25 });
@Niweera
Niweera / add- description.js
Created February 26, 2022 18:43
Add description to the NFT
const addDescription = async (page, description) => {
await page.focus("#description");
await page.keyboard.type(description, { delay: 25 });
};
@Niweera
Niweera / add-link.js
Created February 26, 2022 18:09
Add the external link
@Niweera
Niweera / add-name.js
Created February 26, 2022 18:06
Add name to the NFT
const addName = async (page, name) => {
await page.focus("#name");
await page.keyboard.type(name, { delay: 25 });
};
@Niweera
Niweera / upload-image.js
Last active February 26, 2022 18:58
Upload image to OpenSea
const createAssetURL = `https://opensea.io/collection/${config.COLLECTION_NAME}/assets/create`
const uploadImage = async (page, filepath) => {
await page.bringToFront();
await page.goto(createAssetURL);
await page.waitForSelector("#media");
const elementHandle = await page.$("#media");
await elementHandle.uploadFile(filepath);
};
@Niweera
Niweera / setup-metamask-opensea.js
Last active February 26, 2022 18:57
Set up MetaMask wallet and OpenSea
import puppeteer from "puppeteer";
import * as dappeteer from "@chainsafe/dappeteer";
import config from "../keys";
const createAssetURL = `https://opensea.io/collection/${config.COLLECTION_NAME}/assets/create`
const setUp = async () => {
const browser = await dappeteer.launch(puppeteer, {
metamaskVersion: config.METAMASK_VERSION,
args: ["--no-sandbox", "--disable-setuid-sandbox"],
@Niweera
Niweera / tweetpik-service.js
Last active February 26, 2022 12:55
TweetPik API service
import axios from "axios";
import config from "../keys";
export default class TweetPikService {
async getScreenshot(tweetId) {
const response = await axios.post(
`https://tweetpik.com/api/images`,
{
tweetId,
themeId: config.TWEETPIK_THEME_ID,