def createPad(): id = request.args.get('padID') print(id) c = EtherpadLiteClient( base_params={ 'apikey': 'f42591e743037bc39d530ba6b1550b0d558aed32f3e9f5e8f12cdeaa1a48b0cd' }) padList = c.listAllPads() if id in padList['padIDs']: c.deletePad(padID=id) message = c.createPad(padID=id) message = c.setText(padID=id, text="") return json.dumps(message)
pw = open('/root/.ep_api_key', 'r').read().strip() ep = EtherpadLiteClient(base_params={'apikey': pw}) except: e = sys.exc_info()[0] print 'Problem logging into Etherpad via API: {0}'.format(e) sys.exit(1) chapter_text = open(chapterfile, 'r').read() parts = chapterfile.split('/') lang = parts[9] ver = parts[10] bk = parts[12] chp = parts[13].replace('.usfm.txt', '') if 'psa' not in chapterfile: chp = chp.lstrip('0').zfill(2) pad_name = '-'.join([lang, ver, bk, chp]) i = int(chp) next = link.format(lang, ver, bk, str(i + 1).zfill(2)) if i == 1: prev = '' else: prev = link.format(lang, ver, bk, str(i - 1).zfill(2)) pad_text = '\n'.join([prev, chapter_text, next]) try: ep.createPad(padID=pad_name, text=pad_text) except EtherpadException as e: print '{0}: {1}'.format(e, pad_name)
if __name__ == '__main__': if len(sys.argv) > 1: book = str(sys.argv[1]).strip() else: print 'Please specify the book to load.' sys.exit(1) try: pw = open('/root/.ep_api_key', 'r').read().strip() ep = EtherpadLiteClient(base_params={'apikey': pw}) except: e = sys.exc_info()[0] print 'Problem logging into Etherpad via API: {0}'.format(e) sys.exit(1) book_notes = '{0}/{1}'.format(notes, book) for f in find('*.txt', book_notes): if 'questions' in f: continue pad_text = codecs.open(f, 'r', encoding='utf-8').read() parts = f.split('/') pad_name = '-'.join( ['en', 'bible', book, parts[-2], parts[-1].replace('.txt', '')]) try: ep.createPad(padID=pad_name, text=pad_text) print link.format(pad_name) except EtherpadException as e: print '{0}: {1}'.format(e, pad_name) except UnicodeEncodeError: print 'Unicode error on {0}'.format(pad_name)
# Clean up the title for later. title = title.strip() # Take a SHA-1 hash of the article because that seems to be the most # reliable way of generating a valid padID for Etherpad-Lite. hash.update(title) hash.update(body) pad_id = hash.hexdigest() # Contact Etherpad and create a new pad with the contents of the page. etherpad = EtherpadLiteClient(base_params={'apikey': etherpad_api_key}, api_version=api_version) page_text = str(title) + "\n\n" + str(body) + "\n" try: etherpad.createPad(padID=pad_id, text=page_text) except EtherpadException as e: logger.warn("Etherpad-Lite module threw an exception: " + str(e)) send_message_to_user(str(e)) time.sleep(float(polling_time)) continue # E-mail a success message with a link to the archived page to the # bot's user. subject_line = "Successfully downloaded page '" + title + "'" message = "I have successfully downloaded and parsed the text of the web page '" + title + "'. You can read the page at the URL " + archive_url + pad_id if not email_response(subject_line, message): logger.warn("Unable to e-mail failure notice to the user.") send_message_to_user(message)
def etherpad(**kwargs): # for key, value in kwargs.items(): # print ("%s == %s" %(key, value)) if (len(kwargs) == 0): args = parse_args(sys.argv) else: args = Namespace(**kwargs) if (args.host and args.port and args.user and args.apikey): # print("launch etherpad with %s:%s for user %s and key %s" % (str(args.host), args.port, args.user, str(args.apikey))) print("launch etherpad") else: return 1 URL = "http://" + str(args.host).replace("'", "") + ":" + args.port + "/api" #print("URL ="+URL) sys.stdout.flush() #time.sleep(2) try: client = EtherpadLiteClient( base_url=URL, base_params={"apikey": str(args.apikey).replace("'", "")}, api_version="1", timeout=7000) except Exception as err: traceback.print_exc(file=sys.stderr) print("Error client : %s" % (err)) sys.exit(1) #time.sleep(1) padID = passrandom(20) DATEcourse = re.sub( r'\..*', '', datetime.datetime.isoformat(datetime.datetime.now(), sep='_').replace(":", "-")) try: if (args.etherpadurl): PadURL = args.etherpadurl + padID.decode('utf-8') else: PadURL = padID.decode('utf-8') except: PadURL = padID.decode('utf-8') MESSAGE = "Subject: [Course " + DATEcourse + "] new padID : " + PadURL + " \nHello \nFor your course at " + DATEcourse + ",please use this PadID to put your (machine, login) :\n" + PadURL tf = tempfile.NamedTemporaryFile(mode="w+b", dir="/tmp", prefix="", delete=False) tf.write(MESSAGE.encode('utf-8')) tf.close() print(MESSAGE) sys.stdout.flush() try: if (args.mail): COMMAND = '/sbin/sendmail -F "' + args.user + '" -f ' + args.mail + ' -t ' + args.mail + ' < ' + tf.name os.system(COMMAND) except: pass try: if (args.filestud): import csv with open(args.filestud, newline='') as csvfile: spamreader = csv.reader(csvfile, delimiter=';', quotechar='|') for row in spamreader: destination = row[1] COMMAND = '/sbin/sendmail -F "' + args.user + '" -f ' + args.mail + ' -t ' + destination + ' < ' + tf.name os.system(COMMAND) except: pass try: myauth = client.createAuthor(name=args.user) pad = client.createPad(padID=padID, text=initText) except Exception as err: traceback.print_exc(file=sys.stderr) print("Error create_pad : %s" % (err)) sys.exit(2) # help(pad) # COMMAND=URL+"/1/setText?apikey="+str(APIKEY)+"&padID="+str(padID)+"&text='"+initText+"'" # os.system("curl "+COMMAND) # Wait for students print( "Wait 60s (or more) for students and teacher must finish by 'END' string." ) time.sleep(60) while True: try: Out = client.getText(padID=padID) except Exception as err: traceback.print_exc(file=sys.stderr) print("Error get_text : %s" % (err)) sys.exit(2) # COMMAND=URL+"/1/getText?apikey="+str(APIKEY)+"&padID="+str(padID)+"&jsonp=?" # os.system("curl "+COMMAND) # Build node file. #print(Out) print(Out["text"]) List = Out["text"].replace(initText, "").split("\n") print(List) sys.stdout.flush() if ("END" in List): iEnd = List.index("END") List = List[:iEnd] break else: time.sleep(2) # Créé le tableau des élèves connectés en direct. studfile = "./directconnection.csv" with open(studfile, 'w+') as f: for stud in List: f.write(stud + "\n") f.close() os.system("ls -la " + studfile)