Skip to main content

Posts

Showing posts from April, 2018

sample python program for pushing bulk data

from datetime import datetime from elasticsearch import Elasticsearch from elasticsearch import helpers es = Elasticsearch() actions = [   {     "_index": "tickets-index",     "_type": "tickets",     "_id": j,     "_source": {         "any":"data" + str(j*10),         "name": "lola",         "timestamp": datetime.now()}   }   for j in range(0, 10) ] helpers.bulk(es, actions)

download all videos from a channel final working code

# -*- coding: utf-8 -*- """ Created on Thu Apr 26 12:26:19 2018 @author: kishlay """ import requests  # or urllib import csv import sys reload(sys) import urllib from datetime import date, timedelta , datetime , time import rfc3339 sys.setdefaultencoding('utf-8') # get Youtube Data API Key API_KEY = ""  # insert your API key # youtube channel ID channel_id = ""  # insert Youtube channel ID page_token = "" print('how are u') videos = [] videosExtendTest = [] test = datetime.now() delta = timedelta(5*30) firstDate = test - delta finalFormat = rfc3339.rfc3339(firstDate) #print(finalFormat) #print(test) formatted = rfc3339.rfc3339(test) print(rfc3339.rfc3339(test)) next = True publishedBefore= datetime.now() period = delta finaltime = date(2008,1,1) while True:     publishedAfter = publishedBefore - delta;     print("\n*****outerloop**\n startdate = "+str(publi

python program to download video and add all in a csv file

import requests  # or urllib import csv import sys  reload(sys)  sys.setdefaultencoding('utf-8') # get Youtube Data API Key API_KEY = ""  # insert your API key # youtube channel ID channel_id = ""  # insert Youtube channel ID page_token = "" print('how are u') videos = [] next = True while next:     url = ("https://www.googleapis.com/youtube/v3/search?key="             "{}&channelId={}&part=snippet,id"             "&order=date&maxResults=50&pageToken={}"             ).format(                 API_KEY,                 channel_id,                 page_token             )     resp = requests.get(url)     data = resp.json()     for i in data['items']:         videos.append(i)     # iterate through result pagination     is_next = data.get('nextPageToken')     if is_next:         page_token = is_next     else:         next = False # structuring

amazon transcribe get transcribe result

var AWS = require('aws-sdk'); AWS.config.update({region:'us-west-2', accessKeyId: 'key',   secretAccessKey: 'key'}); var transcribeservice = new AWS.TranscribeService({apiVersion: '2017-10-26'}); var params = {   TranscriptionJobName: 'job name' /* required */ }; transcribeservice.getTranscriptionJob(params, function(err, data) {   if (err) console.log(err, err.stack); // an error occurred   else     console.log(data);           // successful response });

Amazon transcribe

var AWS = require('aws-sdk'); AWS.config.update({region:'us-west-2', accessKeyId: 'key',   secretAccessKey: 'key'}); var transcribeservice = new AWS.TranscribeService({apiVersion: '2017-10-26'}); var params = {   LanguageCode: 'en-US', /* required */   Media: { /* required */     MediaFileUri: 'https://s3-us-west-2.amazonaws.com/randhunt-transcribe-demos/test.flac'   },   MediaFormat: 'flac', /* required */   TranscriptionJobName: 'RandallTest1', /* required */   MediaSampleRateHertz: 44100,   // Settings: {   //   MaxSpeakerLabels: 0,   //   ShowSpeakerLabels: true || false,   //   VocabularyName: 'STRING_VALUE'   // } }; transcribeservice.startTranscriptionJob(params, function(err, data) {   if (err) console.log(err, err.stack); // an error occurred   else     console.log(data);           // successful response }); // var transcribeservice = new AWS.TranscribeService(); // tran

Google speech to text node js code

// Imports the Google Cloud client library const speech = require('@google-cloud/speech'); const fs = require('fs'); var speechToText = function(filetoProcess , callback){ // Creates a client const client = new speech.SpeechClient(); // The name of the audio file to transcribe const fileName = filetoProcess; // Reads a local audio file and converts it to base64 const file = fs.readFileSync(fileName); const audioBytes = file.toString('base64'); // The audio file's encoding, sample rate in hertz, and BCP-47 language code const audio = {   content: audioBytes, }; const config = {   encoding: 'LINEAR16',   sampleRateHertz: 8000,   languageCode: 'en-IN',   profanityFilter: true,   // speechContexts: {   //     phrases:["yes","no"]   //    },   metadata: {            interactionType: "VOICEMAIL",            //industryNaicsCodeOfAudio: 23810,            microphoneDistance: "NEARFIELD

convert mp3 file to wav in node js using ffmpeg

var ffmpeg = require('fluent-ffmpeg'); var track = './test.mp3';//your path to source file console.log("outside"); ffmpeg(track) .format('wav') .on('error', function (err) {     console.log('An error occurred: ' + err.message); }) .on('progress', function (progress) {     // console.log(JSON.stringify(progress));     console.log('Processing: ' + progress.targetSize + ' KB converted'); }) .on('end', function () {     console.log('Processing finished !'); }).output("./test.wav") .run();

inserting retrieving and search data in elastic search

Insert PUT / megacorp / employee / 1 { "first_name" : "John" , "last_name" : "Smith" , "age" : 25 , "about" : "I love to go rock climbing" , "interests" : [ "sports" , "music" ] } Get data GET / megacorp / employee / 1 result: { "_index" : "megacorp" , "_type" : "employee" , "_id" : "1" , "_version" : 1 , "found" : true , "_source" : { "first_name" : "John" , "last_name" : "Smith" , "age" : 25 , "about" : "I love to go rock climbing" , "interests" : [ "sports" , "music" ] } } Search GET / megacorp /

crud in elasticSearch

CRUD in ElasticSearch https://www.elastic.co/guide/en/elasticsearch/reference/2.1/breaking_20_crud_and_routing_changes.html To update we just use put again

stop kibana

sudo - i service kibana stop https://www.elastic.co/guide/en/kibana/current/rpm.html all details of start stop install kibana start kibana in terminal and keep it running the background nohup ./kibana

scrape all urls from youtube playlist

# -*- coding: utf-8 -*- """ Created on Wed Apr  4 14:09:45 2018 @author: kishlay """ from bs4 import BeautifulSoup as bs import requests r = requests.get('https://www.youtube.com/playlist?list=PL3D7BFF1DDBDAAFE5') page = r.text soup=bs(page,'html.parser') res=soup.find_all('a',{'class':'pl-video-title-link'}) for l in res:     print l.get("href")

own function with callback in nodejs

up vote accepted Here's an example of the login function: function login ( username , password , callback ) { var info = { user : username , pwd : password }; request . post ({ url : "https://www.adomain.com/login" , formData : info }, function ( err , response ) { callback ( err , response ); }); } And calling the login function login ( "bob" , "wonderland" , function ( err , result ) { if ( err ) { // login did not succeed } else { // login successful } }); #reference -- stackoverflow

how to use fuse.js in node js

npm i fuse.js --save var options = {   shouldSort: true,   threshold: 0.6,   location: 0,   distance: 100,   maxPatternLength: 32,   minMatchCharLength: 1,   keys: [     "text" ] }; var fuse = new Fuse(list, options); // "list" is the item array var result = fuse.search("silence"); //console.log(list); console.log(result) // list will contains list of elements for search

export in nodejs

var ChromecastAPI = require('chromecast-api') var chromeCast = function(content  , contentType , timeseek){ var browser = new ChromecastAPI.Browser() console.log("browser api"); browser.on('deviceOn', function (device) {   var urlMedia = 'http://commondatastorage.googleapis.com/gtv-videos-bucket/big_buck_bunny_1080p.mp4';   console.log("\n content is "+ content);;   device.play(content, 0, function () {     console.log('Playing in your chromecast ' + timeseek)     if (timeseek) {       device.seek(timeseek,function (err) {               if (err) console.log('Seek forward: ERROR')               else console.log('Seek forward: SUCCESS')           })     }   }) }) } module.exports.chromeCast = chromeCast; // to use in other node js file --> var chromeCast = require('./test.js');