Skip to main content

Posts

Showing posts from July, 2018

inserting and updating in elasticSearch using python

from elasticsearch import Elasticsearch from elasticsearch import helpers import time es = Elasticsearch() individialVideoDocs = [] docs = [] subscriberUserID = [ "kishlay" , "raj" ] allVideosFullText = { "_index" : "pipa" , "_type" : "video" , # "_id": videoId, "_source" : { "SusbcriberUserId" : subscriberUserID, "script" : "alltext" } } docs.append(allVideosFullText) k = helpers.bulk(es, docs) arr = []; time.sleep( 2 ) res = es.search( index = "pipa" , doc_type = "video" , body ={ "query" : { "match" : { "script" : "alltext" }}}) print ( "%d documents found" % res[ 'hits' ][ 'total' ]) # print(res) es.indices.refresh( index = "pipa" ) for doc in res[ 'hits' ][ 'hits' ]: # print("%s) %s" % (doc['_id'], do

add and get list in and from SharedPref android

/** * Save and get ArrayList in SharedPreference */ public void saveArrayList(ArrayList<String> list, String key){ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); SharedPreferences.Editor editor = prefs.edit(); Gson gson = new Gson(); String json = gson.toJson(list); editor.putString(key, json); editor.apply(); // This line is IMPORTANT !!! } public ArrayList<String> getArrayList(String key){ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); Gson gson = new Gson(); String json = prefs.getString(key, null); Type type = new TypeToken<ArrayList<String>>() {}.getType(); return gson.fromJson(json, type); }

Python subprocess get output log for each step

Python get realtime log output of subprocess in python def run_command(command): process = subprocess.Popen((command), stdout =subprocess.PIPE) while True : output = process.stdout.readline() if output == '' and process.poll() is not None : break if output: print (output.strip()) rc = process.poll() return rc if the process is not breaking after completion of task then add this output = output.decode( "utf-8" ) run_command(command) Download python file https://drive.google.com/file/d/16KI7j9ARdGaI9NChNX1w0janQCGedqtc/view?usp=sharing