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
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
Esempio n. 3
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")))
Esempio n. 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()['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'))
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'))
Esempio n. 6
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)
Esempio n. 7
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
Esempio n. 8
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
Esempio n. 9
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)
Esempio n. 10
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
Esempio n. 11
0
def main():
    c = EtherpadLiteClient(base_params={'apikey': cfg.myapikey},
                           base_url=cfg.mybaseURL)
    c.setText(padID=cfg.mypadIDFalse, text=cfg.falsPadText)
Esempio n. 12
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"]
Esempio n. 13
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"]