예제 #1
0
 def preview(self):
     try:
         c = EtherpadLiteClient(base_url=self.get_api_url())
         data = c.getHTML(padID=self.padname)
         return data
     except (HTTPError, URLError):
         return super(Etherpad,self).preview()
def main():
    try:
        pw = open('/usr/share/httpd/.ssh/ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                api_version='1.2.10')
    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)

    all_pads = ep.listAllPads()
    ver_pads = [x for x in all_pads['padIDs'] if 'ulb' in x or 'udb' in x]
    ver_pads.sort()

    redirects = []
    for bk in books.iterkeys():
        bk_pads = [
            x for x in ver_pads if bk.lower() in x and contains_digits(x)
        ]
        bk_pads.sort()
        for p in bk_pads:
            # Skips pad that WA uses for communication (e.g. 'en-ulb-1ti')
            if len(p.split('-')) < 4:
                continue
            chapter = p.split('-')[3]
            content = ep.getText(padID=p)['text']
            if 'Welcome to Etherpad!' in content:
                continue
            redirects.append(u'rewrite /p/{0} /p/{1} permanent;'.format(
                p,
                ep.getReadOnlyID(padID=p)['readOnlyID']))
    print u'\n'.join(sorted(redirects))
예제 #3
0
 def preview(self):
     try:
         c = EtherpadLiteClient(base_url=self.get_api_url())
         data = c.getHTML(padID=self.padname)
         return data
     except (HTTPError, URLError):
         return super(Etherpad, self).preview()
예제 #4
0
def main():
    try:
        pw = open("/usr/share/httpd/.ssh/ep_api_key", "r").read().strip()
        ep = EtherpadLiteClient(base_params={"apikey": pw}, api_version="1.2.10")
    except:
        e = sys.exc_info()[0]
        print "Problem logging into Etherpad via API: {0}".format(e)
        sys.exit(1)

    all_pads = ep.listAllPads()
    ver_pads = [x for x in all_pads["padIDs"] if "ulb" in x or "udb" in x]
    ver_pads.sort()

    redirects = []
    for bk in books.iterkeys():
        bk_pads = [x for x in ver_pads if bk.lower() in x and contains_digits(x)]
        bk_pads.sort()
        for p in bk_pads:
            # Skips pad that WA uses for communication (e.g. 'en-ulb-1ti')
            if len(p.split("-")) < 4:
                continue
            chapter = p.split("-")[3]
            content = ep.getText(padID=p)["text"]
            if "Welcome to Etherpad!" in content:
                continue
            redirects.append(u"rewrite /p/{0} /p/{1} permanent;".format(p, ep.getReadOnlyID(padID=p)["readOnlyID"]))
    print u"\n".join(sorted(redirects))
예제 #5
0
 def EtherMap(self):
     epclient = EtherpadLiteClient({'apikey': self.server.apikey},
                                   self.server.apiurl)
     result = epclient.createAuthorIfNotExistsFor(
         authorMapper=self.user.id.__str__(), name=self.__str__())
     self.authorID = result['authorID']
     return result
def transcribe_to_etherpad(sip_url, etherpad_url, api_key_file, **kwargs):
    api_url = urljoin(etherpad_url, '/api')
    pad_id = etherpad_url.split('/')[-1]

    apikey = open(api_key_file, 'rb').read()
    c = EtherpadLiteClient(base_url=api_url, api_version='1.2.13', base_params={'apikey': apikey})
    for text in transcribe(sip_url, **kwargs):
        c.appendText(padID=pad_id, text=' ' + text)
예제 #7
0
 def __init__(self,
              apikey,
              padID,
              targetFile,
              base_url='http://localhost:9001/api'):
     self._con = EtherpadLiteClient(base_params={'apikey': apikey},
                                    base_url=base_url)
     self._padID = padID
     self._file = targetFile
예제 #8
0
def pasteText(text=None):
    a = request.args.get('a')
    c = EtherpadLiteClient(
        base_params={
            'apikey':
            'f42591e743037bc39d530ba6b1550b0d558aed32f3e9f5e8f12cdeaa1a48b0cd'
        })
    padList = c.listAllPads()
    c.appendText(padID=padList['padIDs'][0], text=a)
    return json.dumps('test')
예제 #9
0
def pasteText(padID=None, text=None):
    text = request.args.get('text')
    padID = request.args.get('padID')
    c = EtherpadLiteClient(
        base_params={
            'apikey':
            'f42591e743037bc39d530ba6b1550b0d558aed32f3e9f5e8f12cdeaa1a48b0cd'
        })
    #padList = c.listAllPads()
    #padList['padIDs']['']
    message = c.appendText(padID=padID, text=text)
    return json.dumps(message)
예제 #10
0
def getPadUsersCount(userCount=None):
    c = EtherpadLiteClient(
        base_params={
            'apikey':
            'f42591e743037bc39d530ba6b1550b0d558aed32f3e9f5e8f12cdeaa1a48b0cd'
        })
    # c = EtherpadLiteClient(base_params={'apikey':'555ddf5d51cba5e38e93d538742a02f7d1b2ea968ca4dcccb983f31c954d632b'})
    padList = c.listAllPads()
    userCount = {}

    for ID in padList['padIDs']:
        userCount[ID] = c.padUsersCount(padID=ID)['padUsersCount']

    return json.dumps(userCount)
class EtherpadFullEngine(BaseEngine):
    def __init__(self, apikey, padID, targetFile, base_url='http://localhost:9001/api'):
        self._con = EtherpadLiteClient(base_params={'apikey': apikey}, base_url=base_url)
        self._padID = padID
        self._file = targetFile

    def timedAction(self):
        with open(self._file, 'r') as fin:
            newText = fin.read()
        newText = sanitize(newText)
        self._con.setText(padID=self._padID, text=newText)

    def exitAction(self):
        pass
예제 #12
0
def main():
    c = EtherpadLiteClient(base_params={'apikey': cfg.myapikey},
                           base_url=cfg.mybaseURL)
    plenum = c.getHTML(padID=cfg.mypadID)
    filename = cfg.filePrefix + '_' + str(
        get_last_Plenum().strftime("%Y.%m.%d")).replace('.', '_')
    write_Plenum(filename, plenum)

    # plenumwiki = str(plenum["html"]).replace("<!DOCTYPE HTML><html><body>", "").replace("</body></html>", "") + "[[Kategorie:" + cfg.wikiKategorie + "]]"
    wikiname = cfg.wikiwikiprefix + '_' + str(
        get_last_Plenum().strftime("%Y_%m"))
    addToWiki(wikiname, str(plenum["html"]))

    c.setText(padID=cfg.mypadID,
              text='Plenum ' + str(get_next_Plenum().strftime("%Y.%m.%d")))
예제 #13
0
def get_etherpad_client():
    """
    Returns an instance of EtherpadLiteClient.
    """
    return EtherpadLiteClient(base_url=settings.ETHERPAD_URL + '/api',
                              api_version='1.2.7',
                              base_params={'apikey': settings.ETHERPAD_KEY})
예제 #14
0
 def client(self):
     if self._client is None:
         self._client = EtherpadLiteClient(
             base_url='%s/api' % self.params['url'],
             api_version='1.2.13',
             base_params={'apikey': self.params['apikey']})
     return self._client
예제 #15
0
파일: app.py 프로젝트: cryu/camper
    def finalize_setup(self):
        """do our own configuration stuff"""
        self.config.dbs = AttributeMapper()
        mydb = self.config.dbs.db = pymongo.Connection(
            self.config.mongodb_host,
            self.config.mongodb_port)[self.config.mongodb_name]
        self.config.dbs.barcamps = db.Barcamps(mydb.barcamps,
                                               app=self,
                                               config=self.config)
        self.config.dbs.sessions = db.Sessions(mydb.sessions,
                                               app=self,
                                               config=self.config)
        self.config.dbs.pages = db.Pages(mydb.pages,
                                         app=self,
                                         config=self.config)
        self.config.dbs.session_comments = db.Comments(mydb.session_comments,
                                                       app=self,
                                                       config=self.config)
        self.module_map.uploader.config.assets = Assets(mydb.assets,
                                                        app=self,
                                                        config=self.config)

        # etherpad connection
        self.config.etherpad = EtherpadLiteClient(
            base_params={'apikey': self.config.ep_api_key},
            base_url=self.config.ep_endpoint)
예제 #16
0
def main():
    try:
        pw = open('/usr/share/httpd/.ssh/ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                                         api_version='1.2.10')
    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)

    all_pads = ep.listAllPads()['padIDs']

    for p in all_pads:
        # Skips pad that WA uses for communication (e.g. 'en-ulb-1ti')
        if len(p.split('-')) < 4:
            continue
        content = u''+ep.getText(padID=p)['text']
        if 'Welcome to Etherpad!' in content or 'ATTENTION' in content:
            continue
        print p
        parts = p.split('-')
        lang = parts[0]
        resource = parts[1]
        bk = parts[2]
        chp = parts[3]
        bk = bk.upper()
        if not bk in books:
            continue
        booknum = books[bk][1]
        content = u'''——————————————————————————————————————
!!!!
!!!!                                                           ATTENTION!!
!!!!          *** THESE FILE ARE NO LONGER EDITED ON ETHERPAD! ***
!!!!
!!!! PLEASE CREATE AN ACCOUNT AT http://github.com AND LET US KNOW YOUR USERNAME
!!!! ON SLACK IN THE #resources CHANNEL OR EMAIL [email protected]
!!!!
!!!! ONCE YOU HAVE ACCESS, YOU CAN EDIT THIS FILE AT
!!!! https://github.com/Door43/{0}-{1}/blob/master/{2}-{3}/{4}.usfm
!!!!
——————————————————————————————————————

{5}
'''.format(resource, lang, booknum, bk, chp, content)
        print p
        ep.setText(padID=p, text=content.encode('utf-8'))
예제 #17
0
    def __init__(self, config):
        AbstractEditor.__init__(self, config)

        self.client = EtherpadLiteClient(
            base_params={'apikey':self.secret},
            base_url=self.apiurl,
            api_version="1.2.12"
        )
예제 #18
0
    def __init__(self,
                 apikey,
                 padID,
                 targetFile,
                 base_url='http://localhost:9001/api',
                 marker=None):
        self._con = EtherpadLiteClient(base_params={'apikey': apikey},
                                       base_url=base_url)
        self._padID = padID
        self._file = targetFile
        if marker == None:
            marker = id_generator(10)
        self._lineMarker = '===== ' + marker + ' ============='

        # Insert line markers at the end of pad
        pad = self._con.getText(padID=self._padID)
        newText = pad['text'] + self._lineMarker + '\n' + self._lineMarker
        self._con.setText(padID=self._padID, text=newText)
예제 #19
0
def user_preferences_updated(sender, instance, *args, **kwargs):
    """This method is executed whenever we get a signal
    that user preferences table had pre_save event which
    signifies an insertion or an update.
    This is a good time to run peer matching.
    """
    user_preference = instance
    peer_preference = random_match(user_preference)

    if peer_preference:
        peer = peer_preference.user_session.user
        user = user_preference.user_session.user
        print("You have been matched with {}".format(peer.username))

        # Create a new peer group for the user and the peer
        pad_group = create_or_get_pad_group(user, peer)

        # Create a new pad for the user and the peer
        pad = Pad(name=get_pad_name(), server=pad_group.server, group=pad_group)
        pad.save()

        # Write a question to the pad
        question = None
        concept = user_preference.concept
        questions = Questions.objects.filter(Q(concepts__name__icontains=concept.name))
        if questions:
            question_index = random.randint(0, questions.count() - 1)
            question = questions[question_index]
        else:
            raise Exception(
            "No questions found in the database for concept {}".format(
                concept.name))

        if question:
            epclient = EtherpadLiteClient({'apikey':pad.server.apikey}, pad.server.apiurl)
            epclient.setText(padID=pad.padid, text=question.description)

         # Mark user and peer in collaborating state
        UserState.objects.filter(user_preference=user_preference).update(state='C')
        UserState.objects.filter(user_preference=peer_preference).update(state='C')

        # Save the pad the users will be using
        UserState.objects.filter(user_preference=user_preference).update(pad=pad)
        UserState.objects.filter(user_preference=peer_preference).update(pad=pad)
예제 #20
0
class EtherpadFullEngine(BaseEngine):
    def __init__(self,
                 apikey,
                 padID,
                 targetFile,
                 base_url='http://localhost:9001/api'):
        self._con = EtherpadLiteClient(base_params={'apikey': apikey},
                                       base_url=base_url)
        self._padID = padID
        self._file = targetFile

    def timedAction(self):
        with open(self._file, 'r') as fin:
            newText = fin.read()
        newText = sanitize(newText)
        self._con.setText(padID=self._padID, text=newText)

    def exitAction(self):
        pass
예제 #21
0
def main(slug, ver):
    today = ''.join(str(datetime.date.today()).rsplit('-')[0:3])
    try:
        pw = open('/usr/share/httpd/.ssh/ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                                         api_version='1.2.10')

    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)

    all_pads = ep.listAllPads()
    ver_pads = [x for x in all_pads['padIDs'] if slug.lower() in x]
    ver_pads.sort()

    if ver.lower() == 'draft':
        outdir = draftout.format(slug.lower(), 'en')
    elif ver.lower() == 'test':
        outdir = testout.format(slug.lower(), 'en')
    else:
        outdir = baseout.format(slug.lower(), 'en')

    books_published = save(ver_pads, outdir, slug, ep, ver)
    status = { "slug": slug.lower(),
               "name": names[slug],
               "lang": "en",
               "date_modified": today,
               "books_published": books_published,
               "status": { "checking_entity": "Wycliffe Associates",
                           "checking_level": "3",
                           "comments": "Original source text",
                           "contributors": "Wycliffe Associates",
                           "publish_date": today,
                           "source_text": "en",
                           "source_text_version": ver,
                           "version": ver
                          }
             }
    writeJSON('{0}/status.json'.format(outdir), status)
    writeFile('{0}/LICENSE.usfm'.format(outdir), LICENSE.format(ver,
                                                    names[slug], basis[slug]))
    print "Check {0} and do a git push".format(outdir)
예제 #22
0
def main(slug, outdir):
    try:
        pw = open('/usr/share/httpd/.ssh/ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                api_version='1.2.10')
    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)

    all_pads = ep.listAllPads()
    ver_pads = [x for x in all_pads['padIDs'] if slug.lower() in x]
    ver_pads.sort()

    outdir = outdir.format(slug.lower(), 'en')

    for bk in books.iterkeys():
        bk_pads = [
            x for x in ver_pads if bk.lower() in x and contains_digits(x)
        ]
        bk_pads.sort()
        content = []
        for p in bk_pads:
            # Skips pad that WA uses for communication (e.g. 'en-ulb-1ti')
            if len(p.split('-')) < 4:
                continue
            chapter = p.split('-')[3]
            content = ep.getText(padID=p)['text']
            if 'Welcome to Etherpad!' in content:
                continue
            content = httpsre.sub(u'', content)
            content = srre.sub(u'', content)
            content = s1re.sub(u'', content)
            content = s_re.sub(u'', content)
            bookdir = u'{0}/{1}-{2}'.format(outdir, books[bk][1], bk)
            if not os.path.exists(bookdir):
                os.makedirs(bookdir)
            outfile = u'{0}/{1}.usfm'.format(bookdir, chapter)
            writeFile(outfile, u''.join(content))

    print u"\nGenerated files in {0}. Done.".format(outdir)
예제 #23
0
    def __init__(self, apikey, padID, targetFile, base_url='http://localhost:9001/api', marker=None):
        self._con = EtherpadLiteClient(base_params={'apikey': apikey}, base_url=base_url)
        self._padID = padID
        self._file = targetFile
        if marker==None:
            marker = id_generator(10)
        self._lineMarker = '===== ' + marker + ' ============='

        # Insert line markers at the end of pad
        pad = self._con.getText(padID=self._padID)
        newText = pad['text'] + self._lineMarker + '\n' + self._lineMarker
        self._con.setText(padID=self._padID, text=newText)
예제 #24
0
def main():
    try:
        pw = open('/usr/share/httpd/.ssh/ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                api_version='1.2.10')
    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)

    all_pads = ep.listAllPads()
    ver_pads = [x for x in all_pads['padIDs'] if x.startswith(u'ta-')]
    ver_pads.sort()

    redirects = []
    for p in ver_pads:
        content = ep.getText(padID=p)['text']
        if 'Welcome to Etherpad!' in content:
            continue
        redirects.append(u'rewrite /p/{0} /p/{1} permanent;'.format(p, ep.getReadOnlyID(padID=p)['readOnlyID']))
    print u'\n'.join(sorted(redirects))
예제 #25
0
class EtherpadSectionEngine(BaseEngine):
    def __init__(self, apikey, padID, targetFile, base_url='http://localhost:9001/api', marker=None):
        self._con = EtherpadLiteClient(base_params={'apikey': apikey}, base_url=base_url)
        self._padID = padID
        self._file = targetFile
        if marker==None:
            marker = id_generator(10)
        self._lineMarker = '===== ' + marker + ' ============='

        # Insert line markers at the end of pad
        pad = self._con.getText(padID=self._padID)
        newText = pad['text'] + self._lineMarker + '\n' + self._lineMarker
        self._con.setText(padID=self._padID, text=newText)

    def timedAction(self):
        with open(self._file, 'r') as fin:
            fileText = fin.read()
        fileText = sanitize(fileText)
        pad = self._con.getText(padID=self._padID)
        text = pad['text']
        parts = text.split(self._lineMarker)
        newText = parts[0] + \
                  self._lineMarker + '\n' + \
                  fileText + '\n' + \
                  self._lineMarker + \
                  parts[2]
        self._con.setText(padID=self._padID, text=newText)

    def exitAction(self):
        pass
예제 #26
0
def main(slug, outdir):
    try:
        pw = open('/usr/share/httpd/.ssh/ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                                         api_version='1.2.10')
    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)

    all_pads = ep.listAllPads()
    ver_pads = [x for x in all_pads['padIDs'] if slug.lower() in x]
    ver_pads.sort()

    outdir = outdir.format(slug.lower(), 'en')

    for bk in books.iterkeys():
        bk_pads = [x for x in ver_pads if bk.lower() in x and contains_digits(x)]
        bk_pads.sort()
        content = []
        for p in bk_pads:
            # Skips pad that WA uses for communication (e.g. 'en-ulb-1ti')
            if len(p.split('-')) < 4:
                continue
            chapter = p.split('-')[3]
            content = ep.getText(padID=p)['text']
            if 'Welcome to Etherpad!' in content:
                continue
            content = httpsre.sub(u'', content)
            content = srre.sub(u'', content)
            content = s1re.sub(u'', content)
            content = s_re.sub(u'', content)
            bookdir = u'{0}/{1}-{2}'.format(outdir, books[bk][1], bk)
            if not os.path.exists(bookdir):
                os.makedirs(bookdir)
            outfile = u'{0}/{1}.usfm'.format(bookdir, chapter)
            writeFile(outfile, u''.join(content))

    print u"\nGenerated files in {0}. Done.".format(outdir)
def main():
    try:
        pw = open('/usr/share/httpd/.ssh/ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                api_version='1.2.10')
    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)

    all_pads = ep.listAllPads()
    ver_pads = [x for x in all_pads['padIDs'] if x.startswith(u'ta-')]
    ver_pads.sort()

    redirects = []
    for p in ver_pads:
        content = ep.getText(padID=p)['text']
        if 'Welcome to Etherpad!' in content:
            continue
        redirects.append(u'rewrite /p/{0} /p/{1} permanent;'.format(
            p,
            ep.getReadOnlyID(padID=p)['readOnlyID']))
    print u'\n'.join(sorted(redirects))
예제 #28
0
def main():
    try:
        pw = open('/usr/share/httpd/.ssh/ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                api_version='1.2.10')
    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)

    namespace = u'ta-'

    all_pads = ep.listAllPads()
    ver_pads = [x for x in all_pads['padIDs'] if x.startswith(namespace)]
    ver_pads.sort()

    for p in ver_pads:
        content = []
        # Skips pad that WA uses for communication (e.g. 'en-ulb-1ti')
        content = ep.getText(padID=p)['text']
        if 'Welcome to Etherpad!' in content:
            continue
        print u"rewrite /p/" + p + ""
예제 #29
0
def main():
    try:
        pw = open('/usr/share/httpd/.ssh/ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                api_version='1.2.10')
    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)

    namespace = u'ta-'

    all_pads = ep.listAllPads()
    ver_pads = [x for x in all_pads['padIDs'] if x.startswith(namespace)]
    ver_pads.sort()

    for p in ver_pads:
        content = []
        # Skips pad that WA uses for communication (e.g. 'en-ulb-1ti')
        content = ep.getText(padID=p)['text']
        if 'Welcome to Etherpad!' in content:
            continue
        print u"rewrite /p/"+p+""
예제 #30
0
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)
예제 #31
0
파일: app.py 프로젝트: sk1p/camper
    def finalize_setup(self):
        """do our own configuration stuff"""
        self.config.dbs = AttributeMapper()
        mydb = self.config.dbs.db = pymongo.MongoClient(self.config.mongodb_url)[self.config.mongodb_name]
        self.config.dbs.barcamps = db.Barcamps(mydb.barcamps, app=self, config=self.config)
        self.config.dbs.sessions = db.Sessions(mydb.sessions, app=self, config=self.config)
        self.config.dbs.pages = db.Pages(mydb.pages, app=self, config=self.config)
        self.config.dbs.blog = db.BlogEntries(mydb.blog, app=self, config=self.config)
        self.config.dbs.galleries = db.ImageGalleries(mydb.galleries, app=self, config=self.config)
        self.config.dbs.session_comments = db.Comments(mydb.session_comments, app=self, config=self.config)
        self.config.dbs.participant_data = db.DataForms(mydb.participant_data, app=self, config=self.config)
        self.config.dbs.tickets = db.Tickets(mydb.tickets, app=self, config=self.config)
        self.config.dbs.userfavs = db.UserFavs(mydb.userfavs, app=self, config=self.config)
        self.module_map.uploader.config.assets = Assets(mydb.assets, app=self, config=self.config)

        # etherpad connection
        self.config.etherpad = EtherpadLiteClient(
            base_params={'apikey': self.config.ep_api_key},
            base_url=self.config.ep_endpoint
        )
예제 #32
0
def main():
    try:
        pw = open('/usr/share/httpd/.ssh/ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                api_version='1.2.10')
    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)

    all_pads = ep.listAllPads()['padIDs']

    for p in all_pads:
        # Skips pad that WA uses for communication (e.g. 'en-ulb-1ti')
        if len(p.split('-')) < 4:
            continue
        content = u'' + ep.getText(padID=p)['text']
        if 'Welcome to Etherpad!' in content or 'ATTENTION' in content:
            continue
        print p
        parts = p.split('-')
        lang = parts[0]
        resource = parts[1]
        bk = parts[2]
        chp = parts[3]
        bk = bk.upper()
        if not bk in books:
            continue
        booknum = books[bk][1]
        content = u'''——————————————————————————————————————
!!!!
!!!!                                                           ATTENTION!!
!!!!          *** THESE FILE ARE NO LONGER EDITED ON ETHERPAD! ***
!!!!
!!!! PLEASE CREATE AN ACCOUNT AT http://github.com AND LET US KNOW YOUR USERNAME
!!!! ON SLACK IN THE #resources CHANNEL OR EMAIL [email protected]
!!!!
!!!! ONCE YOU HAVE ACCESS, YOU CAN EDIT THIS FILE AT
!!!! https://github.com/Door43/{0}-{1}/blob/master/{2}-{3}/{4}.usfm
!!!!
——————————————————————————————————————

{5}
'''.format(resource, lang, booknum, bk, chp, content)
        print p
        ep.setText(padID=p, text=content.encode('utf-8'))
예제 #33
0
def main(args):
    try:
        pw = open('/usr/share/httpd/.ssh/ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                                         api_version='1.2.10')

    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)

    all_pads = ep.listAllPads()
    ver_pads = [x for x in all_pads['padIDs'] if args.slug.lower() in x]
    ver_pads.sort()
    bk_pads = [x for x in ver_pads if contains_digits(x)]

    for p in bk_pads:
        if p != 'en-en-ulb-gen-01': continue
        # Get text
        p_orig = ep.getText(padID=p)['text']
        p_content = p_orig

        # Run transformations
        if args.hyphenfix:
            p_content = hyphenfixre.sub(u'—', p_content)
            p_content = p_content.replace(u' — ', u'—')
        #if args.versefix:
            #p_content = verseFix(p_content)
        #if args.smartquotes:
            #p_content = smartquotes(p_content)

        # save text
        if p_orig != p_content:
            print 'Updating {0}'.format(p)
            try:
                ep.setText(padID=p, text=p_content.encode('utf-8'))
            except EtherpadException as e:
                print '{0}: {1}'.format(e, p)
        break
예제 #34
0
class EtherpadSectionEngine(BaseEngine):
    def __init__(self,
                 apikey,
                 padID,
                 targetFile,
                 base_url='http://localhost:9001/api',
                 marker=None):
        self._con = EtherpadLiteClient(base_params={'apikey': apikey},
                                       base_url=base_url)
        self._padID = padID
        self._file = targetFile
        if marker == None:
            marker = id_generator(10)
        self._lineMarker = '===== ' + marker + ' ============='

        # Insert line markers at the end of pad
        pad = self._con.getText(padID=self._padID)
        newText = pad['text'] + self._lineMarker + '\n' + self._lineMarker
        self._con.setText(padID=self._padID, text=newText)

    def timedAction(self):
        with open(self._file, 'r') as fin:
            fileText = fin.read()
        fileText = sanitize(fileText)
        pad = self._con.getText(padID=self._padID)
        text = pad['text']
        parts = text.split(self._lineMarker)
        newText = parts[0] + \
                  self._lineMarker + '\n' + \
                  fileText + '\n' + \
                  self._lineMarker + \
                  parts[2]
        self._con.setText(padID=self._padID, text=newText)

    def exitAction(self):
        pass
예제 #35
0
class EtherpadEditor(AbstractEditor):

    def __init__(self, config):
        AbstractEditor.__init__(self, config)

        self.client = EtherpadLiteClient(
            base_params={'apikey':self.secret},
            base_url=self.apiurl,
            api_version="1.2.12"
        )

    def _get_authorid_for_user(self, user):
        name = user.username
        color = user.color
        if color is not None and len(color) > 0:
            color = '#' + color
        return self.client.createAuthorIfNotExistsFor(authorMapper=name, name=name, color=color)["authorID"]

    def _get_groupid_for_document(self, document):
        if isinstance(document, str):
            docname = document
        else:
            docname = document.name
        return self.client.createGroupIfNotExistsFor(groupMapper=docname)["groupID"]

    def _get_padid_for_document(self, document):
        group = self._get_groupid_for_document(document)
        return group + "$" + document.name

    def get_urlname_for_document(self, document):
        return self._get_padid_for_document(document)

    def generate_session(self, document, user):
        tomorrow = datetime.today() + timedelta(days=1)
        author = self._get_authorid_for_user(user)
        group = self._get_groupid_for_document(document)
        session = self.client.createSession(groupID=group, authorID=author, validUntil=tomorrow.timestamp())["sessionID"]
        return session

    def delete_session(self, sid):
        self.client.deleteSession(sessionID=sid)

    def delete_sessions(self, user):
        author = self._get_authorid_for_user(user)
        sessions = self.client.listSessionsOfAuthor(authorID=author)
        for sid in sessions:
            self.delete_session(sid)

    def create_document(self, document):
        group = self._get_groupid_for_document(document)
        try:
            self.client.createGroupPad(groupID=group, padName=document.name)
        except EtherpadException as e:
            if str(e) == 'padName does already exist':
                self.set_document_text(document, '')
            else:
                raise

    def delete_document(self, document):
        pad_id = self._get_padid_for_document(document)
        self.client.deletePad(padID=pad_id)

    def set_document_text(self, document, text):
        pad_id = self._get_padid_for_document(document)
        self.client.setText(padID=pad_id, text=text)

    def get_document_text(self, document):
        pad_id = self._get_padid_for_document(document)
        return self.client.getText(padID=pad_id)["text"]
예제 #36
0
link = 'https://pad.door43.org/p/{0}-{1}-{2}-{3}'
nextfmt = 'https://pad.door43.org/p/en-udb-luk-01'


if __name__ == '__main__':
    if len(sys.argv) > 1:
        chapterfile = str(sys.argv[1]).strip()
        if not os.path.exists(chapterfile):
            print 'File not found: {0}'.format(chapterfile)
            sys.exit(1)
    else:
        print 'Please specify the file 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)

    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])
예제 #37
0
def find(pattern, top):
    # Based off of http://www.dabeaz.com/generators-uk/genfind.py
    for path, dirlist, filelist in os.walk(top):
        for name in fnmatch.filter(filelist, pattern):
            yield os.path.join(path, 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)
예제 #38
0
    except:
        print "  => ERROR retrieving %s\nCheck the URL" % url
        sys.exit(1)
    return request


if __name__ == '__main__':
    if len(sys.argv) > 1:
        pad_name = str(sys.argv[1]).strip()
        if 'ulb' not in pad_name:
            print 'Please specify ULB pad to chunk.'
            sys.exit(1)
    else:
        print 'Please specify the pad to chunk.'
        sys.exit(1)
    try:
        pw = open('/usr/share/httpd/.ssh/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)

    lang,ver,bk,chp = pad_name.split('-')
    ulb = ep.getText(padID=pad_name)
    udb = ep.getText(padID=pad_name.replace('ulb', 'udb'))
    tft = getURL(TFTURL.format(bk, chp.zfill(3)))

    chunked = splice(ulb['text'], udb['text'], tft, bk, chp)
    writeChunks(chunked)
예제 #39
0
class Etherpad(object):
    def __init__(self):
        self.api = EtherpadLiteClient(
            api_version='1.2.1',
            base_url='{0}/api/'.format(settings.ETHERPAD_URL),
            base_params={'apikey': settings.ETHERPAD_API_KEY})

    def _get_ep_user(self, user):
        ldap_user = user.get_ldapuser()
        return self.api.createAuthorIfNotExistsFor(
                authorMapper=user.id,
                name=ldap_user.display_name.encode('utf-8'),
        )['authorID']

    def create_group_pad(self, group_name, pad_name):
        """
        Creates a Pad for Group
        """
        try:
            self.api.createGroupPad(
                groupID=self.get_group_id(group_name),
                padName=pad_name.encode('utf-8'))
        except EtherpadException as e:
            # test if pad was already created, if so it's ok
            if e.message == "padName does already exist":
                return
            raise

    def create_session(self, user, group_name):
        group = self.get_group_id(group_name)
        user_ep = self._get_ep_user(user)
        # first we delete old sessions
        activ_sessions = self.api.listSessionsOfGroup(groupID=group)
        if activ_sessions:
            for sessionID, data in activ_sessions.items():
                if data['authorID'] == user_ep:
                    if data['validUntil'] > time.time() + MIN_SESSION_REMAIN_TIME:
                        # There is a valid session with over 6 hours
                        # remaining time
                        return
                    else:
                        # we delete the old Session so the user has not two
                        # on the same group. (technickal no problem,
                        # but the cookies will have more data
                        self.api.deleteSession(sessionID=sessionID)
        # we create a new session
        self.api.createSession(
                groupID = group,
                authorID = user_ep,
                validUntil = time.time() + SESSION_DURATION)

    def get_session_cookie(self, user):
        sessions = self.api.listSessionsOfAuthor(
                        authorID= self._get_ep_user(user)
                        )
        # We have to escape the comma with %2C because otherwise Django's
        # HttpResponse.set_cookie escapes it, but Etherpad can't read
        # the escaped value correctly.
        sessions_cookie = '%2C'.join(sessions.keys())
        return sessions_cookie

    def get_group_id(self, group_name):
        return self.api.createGroupIfNotExistsFor(
                groupMapper=group_name.encode('utf-8')
                )["groupID"]

    def get_group_pads(self, group_name):
        try:
            return self.api.listPads(groupID=self.get_group_id(group_name))['padIDs']
        except EtherpadException as e:
            if e.message == "groupID does not exist":
                # no pads for this group
                return []
            raise

    def delete_pad(self, pad_name):
        try:
            self.api.deletePad(padID=pad_name.encode('utf-8'))
        except EtherpadException as e:
            if e.message == "padID does not exist":
                return
            raise

    def delete_group(self, group_name):
        self.api.deleteGroup(groupID=self.get_group_id(group_name))

    def get_last_edit(self, pad_name):
        try:
            return float(self.api.getLastEdited(padID=pad_name.encode('utf-8'))['lastEdited']) / 1000
        except EtherpadException as e:
            if e.message == "padID does not exist":
                return 0
            raise
        except TypeError:
            # LastEdited is None
            return 0

    def get_html(self, pad_name):
        try:
            return self.api.getHTML(padID=pad_name.encode('utf-8'))['html']
        except EtherpadException as e:
            if e.message == "padID does not exist":
                return ""
            raise
예제 #40
0
 def __init__(self):
     self.api = EtherpadLiteClient(
         api_version='1.2.1',
         base_url='{0}/api/'.format(settings.ETHERPAD_URL),
         base_params={'apikey': settings.ETHERPAD_API_KEY})
 def __init__(self, apikey, padID, targetFile, base_url='http://localhost:9001/api'):
     self._con = EtherpadLiteClient(base_params={'apikey': apikey}, base_url=base_url)
     self._padID = padID
     self._file = targetFile
예제 #42
0
from etherpad_lite import EtherpadLiteClient

etherpad_client = EtherpadLiteClient(
    base_params={
        "apikey":
        "5da9f78b8445e157e04332920ba299aaa2aa54dc1fd9ab55519c4e5165fb6c88"
    },
    base_url="http://etherpad:9001/api",
)
예제 #43
0
def _init_client():
    """Initialises the etherpad lite client"""
    return EtherpadLiteClient(
        base_url=settings.COSINNUS_ETHERPAD_BASE_URL,
        api_version='1.2.7',
        base_params={'apikey': settings.COSINNUS_ETHERPAD_API_KEY})
예제 #44
0
</div></div>
</div>
</body>
</html>"""


def writeFile(f, content):
    out = codecs.open(f, encoding="utf-8", mode="w")
    out.write(content)
    out.close()


if __name__ == "__main__":
    try:
        pw = open("/root/.ep_api_key", "r").read().strip()
        ep = EtherpadLiteClient(base_params={"apikey": pw}, api_version="1.2.10")
    except:
        e = sys.exc_info()[0]
        print "Problem logging into Etherpad via API: {0}".format(e)
        sys.exit(1)
    os.environ["TZ"] = "US/Eastern"
    pads = ep.listAllPads()
    recent = []
    for p in pads["padIDs"]:
        if not p:
            continue
        recent.append((p, ep.getLastEdited(padID=p)["lastEdited"]))

    recent_sorted = sorted(recent, key=lambda p: p[1], reverse=True)
    recent_html = []
    for i in recent_sorted:
예제 #45
0
</div></div>
</div>
</body>
</html>'''


def writeFile(f, content):
    out = codecs.open(f, encoding='utf-8', mode='w')
    out.write(content)
    out.close()


if __name__ == '__main__':
    try:
        pw = open('/root/.ep_api_key', 'r').read().strip()
        ep = EtherpadLiteClient(base_params={'apikey': pw},
                                api_version='1.2.10')
    except:
        e = sys.exc_info()[0]
        print 'Problem logging into Etherpad via API: {0}'.format(e)
        sys.exit(1)
    os.environ['TZ'] = 'US/Eastern'
    pads = ep.listAllPads()
    recent = []
    for p in pads['padIDs']:
        if not p:
            continue
        recent.append((p, ep.getLastEdited(padID=p)['lastEdited']))

    recent_sorted = sorted(recent, key=lambda p: p[1], reverse=True)
    recent_html = []
    for i in recent_sorted:
예제 #46
0
from etherpad_lite import EtherpadLiteClient
import os
import requests
import click
import ftfy

URL = 'http://yourserver:yourport'
APIKEY = 'inser your key here'

client = EtherpadLiteClient(base_url=URL + '/api',
                            base_params={'apikey': APIKEY},
                            api_version='1.2.9')

os.makedirs('exported_pads', exist_ok=True)

pad_list = client.listAllPads()['padIDs']
with click.progressbar(pad_list) as progress_bar:
    for pad_name in progress_bar:
        with open('exported_pads' + os.sep + pad_name + '.txt', 'w') as file:
            pad_content = ftfy.fix_text(requests.get(URL + '/p/' + pad_name + '/export/txt').text)
            file.write(pad_content)
예제 #47
0
def main():
    c = EtherpadLiteClient(base_params={'apikey': cfg.myapikey},
                           base_url=cfg.mybaseURL)
    c.setText(padID=cfg.mypadIDFalse, text=cfg.falsPadText)
예제 #48
0
 def epclient(self):
     return EtherpadLiteClient({'apikey': self.server.apikey},
                               self.server.apiurl)
예제 #49
0
    fixed_text = fixed_text.replace(u' — ', u'—')

    return fixed_text


if __name__ == '__main__':
    if len(sys.argv) > 1:
        pad_name = str(sys.argv[1]).strip()
        if 'ulb' not in pad_name:
            print 'Please specify ULB pad to chunk.'
            sys.exit(1)
    else:
        print 'Please specify the pad to chunk.'
        sys.exit(1)
    try:
        pw = open('/usr/share/httpd/.ssh/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)

    lang, ver, bk, chp = pad_name.split('-')
    ulb = ep.getText(padID=pad_name)
    udb = ep.getText(padID=pad_name.replace('ulb', 'udb'))
    tft = getURL(TFTURL.format(bk, chp.zfill(3)))

    chunked = splice(fix_text(ulb['text']), fix_text(udb['text']), tft, bk,
                     chp)
    writeChunks(chunked)