Example #1
0
def generateRSS(section):
    posts = section['posts']

    postUrl = "posts"

    if not section['root']:
        postUrl = '/'.join([section['directory'], "posts"])

    xmlDirectory = 'output/rss/'
    createDirectory(xmlDirectory)

    xmlItems = []

    for post in posts:
        title = post['title']
        link = '/'.join([cfg.site['url'], postUrl, post['slug']])

        dateRaw = convertToRawDate(post['date'])
        date = datetime.fromisoformat(dateRaw).strftime("%a, %d %b %Y %X")
                
        summary = post['summary']

        xmlItems.append("""
            <item>
                <title>{title}</title>
                <link>{link}</link>
                <guid isPermaLink="true">{link}</guid>
                <pubDate>{date} GMT</pubDate>
                <description>{summary}</description>
            </item>
        """.format(title=htmlentities.encode(title), link=link, date=date, summary=htmlentities.encode(summary))
        )
    
    rssTitle = ' | '.join([section['seoTitle'], cfg.site['name']])
    rssLink = cfg.site['url'] if section['root'] else '/'.join([cfg.site['url'], section['directory']])
    rssDescription = section['seoDescription']

    xml = """
      <?xml version="1.0" encoding="UTF-8"?>
      <rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
        <channel>
            <title>{title}</title>
            <link>{link}</link>
            <description>{description}</description>
            <atom:link href="{link}" rel="self" type="application/rss+xml" />
            {items}
        </channel>
       </rss>
    """.format(title=htmlentities.encode(rssTitle), link=rssLink, description=htmlentities.encode(rssDescription), items=''.join(xmlItems).strip())

    filepath = xmlDirectory + section['directory'] + '.xml'
    writeToFile(filepath, xml.strip().encode('utf-8'))
Example #2
0
def _update_(group_id):
    try:
        group_id = int(group_id)
    except ValueError:
        return {"error": Messages.INT_VALUE_ERROR}, 400

    group = Groups.query.filter_by(id=group_id).first()

    if not group:
        return {"error": Messages.GROUP_NOT_EXISTS}, 404

    post = request.get_json()

    name = post.get("name")
    color = post.get("color")

    if name:
        if Groups.query.filter_by(name=name).first():
            return {"error": Messages.GROUP_EXISTS}, 400

        name = htmlentities.encode(name)
        group.name = name

    if color:
        if not correct_hex_number(color):
            return {"error": Messages.INVALID_HEX}, 400
        group.color = color

    db.session.commit()

    return {"ok": Messages.GROUP_UPDATED}
Example #3
0
def _update_(task_id):
    task = Tasks.query.filter_by(id=task_id).first()

    if not task:
        return {
            "error": Messages.TASK_NOT_FOUND.replace("<id>", str(task_id))
        }, 404

    post = request.get_json()

    name = post.get("name")
    tasks_count = post.get("tasks-count")
    deadline_timestamp = post.get("deadline")

    if name:
        name = htmlentities.encode(name)
        task.name = name

    if tasks_count:
        try:
            tasks_count = int(tasks_count)
        except ValueError:
            return {"error": Messages.INT_VALUE_ERROR}, 400

        if tasks_count > 26:
            return {"error": Messages.MAX_TASKS_COUNT}, 400

        task.tasks_count = tasks_count

    if deadline_timestamp:
        task.deadline_timestamp = deadline_timestamp

    db.session.commit()

    return {"ok": Messages.TASK_UPDATED}
Example #4
0
def _create_():
    post = request.get_json()

    name = post.get("name")
    group_id = post.get("group-id")
    tasks_count = post.get("tasks-count")
    deadline_timestamp = post.get("deadline")

    if not name:
        return {"error": Messages.TASK_NAME_REQUIRED}, 400

    if not group_id:
        return {"error": Messages.GROUP_ID_REQUIRED}, 400

    if not tasks_count:
        return {"error": Messages.TASKS_COUNT_REQUIRED}, 400

    if not deadline_timestamp:
        return {"error": Messages.DEADLINE_REQUIRED}, 400

    if not Groups.query.filter_by(id=group_id).first():
        return {
            "error":
            Messages.GROUP_ID_NOT_FOUND.replace("<id>", str(group_id))
        }, 404

    try:
        tasks_count = int(tasks_count)
    except ValueError:
        return {"error": Messages.INT_VALUE_ERROR}, 400

    if tasks_count > 26:
        return {"error": Messages.MAX_TASKS_COUNT}, 400

    name = htmlentities.encode(name)

    new_task = Tasks(name=name,
                     group_id=group_id,
                     tasks_count=tasks_count,
                     deadline_timestamp=deadline_timestamp)

    db.session.add(new_task)
    db.session.commit()

    return {"ok": Messages.TASK_CREADTED}
Example #5
0
def info(message):
    message_str = str()
    reply = message.reply_to_message
    chat_id = str(message.chat.id)
    if(reply is None):
      return 
    first_name = reply.from_user.first_name
    username = reply.from_user.username
    last_name = reply.from_user.last_name
    user_id = str(reply.from_user.id)
    date_str = '<b>' +'Date: '+ '</b>' + '<code>' + str(time.strftime('%a, %d %b %Y %H:%M:%S +0000', time.localtime(reply.date))) + '</code>'
    if(reply.sticker is not None):
      message_str = '<b>'+'Media type: </b>'+ 'sticker'+'\n'

    elif(reply.audio is not None):
      message_str = '<b>'+'Media type: </b>'+ 'audio'+ '\n'

    elif(reply.location is not None):
      message_str = '<b>'+'Media type: </b>'+ 'location'+ '\n'

    elif(reply.video is not None):
      message_str = '<b>'+'Media type: </b>'+ 'video'+'\n'

    elif(reply.video_note is not None):
      message_str = '<b>'+'Media type: </b>'+ 'video_note'+'\n' 

    elif(reply.audio is not None):
      message_str = '<b>'+'Media type: </b>'+  'audio'+ '\n'

    elif(reply.photo is not None):
      message_str = '<b>'+'Media type: </b>'+ 'photo'+ '\n'

    elif(reply.document is not None):
      message_str = '<b>'+'Media type: </b>'+ 'document'+ '\n'

    elif(reply.text is not None):
      reply_text = htmlentities.encode(reply.text)
      message_str ='<b>'+ 'Message: '+ '</b>'+ reply_text + '\n'

    user_str = '<b>' + 'User: '******'</b>' + Nonestr(first_name) + Nonestr(last_name) + '(' + Nonestr(username) + ('/' if len(Nonestr(username)) > 0 else "") + '<code>' + user_id  + '</code>'  + ')' + '\n'
    answer = message_str + user_str + date_str
    RoyalTrident_bot.send_message(chat_id, answer,parse_mode = 'HTML')
Example #6
0
def save():

    try:
        email = session['email']
        username = session['username']
        print(request)
        data = request.get_json()['data']
        with open("a.txt", 'w') as op:
            op.write(str(request.get_json))

        database.content.insert_one({
            "username": username,
            "email": email,
            "content": htmlentities.encode(data),
            "title": request.get_json()['title'],
            "desc": request.get_json()['desc']
        })
        return jsonify({"status": True})

    except Exception as e:
        return jsonify({"status": False})
Example #7
0
def siginin():
    if request.method == "POST":
        username = request.form.get('username')
        password = request.form.get('password')
        email = request.form.get('email')

        password_hash = bcrypt.generate_password_hash(str(password))
        no_of_user = database.person.count_documents({"email": email})
        if no_of_user == 0:
            record = {
                "username": str(htmlentities.encode(username)),
                "password": password_hash,
                "email": email
            }

            database.person.insert_one(record)

            flash("the insertion occur succesfully", "danger")
        else:

            flash("The email is already in use", "danger")

    return render_template('home.html')
Example #8
0
def _create_():
    post = request.get_json()

    name = post.get("name")
    color = post.get("color")

    if not name:
        return {"errro": Messages.NAME_REQUIRED}, 400

    if not color:
        return {"error": Messages.COLOR_REQIURED}, 400

    if Groups.query.filter_by(name=name).first():
        return {"error": Messages.GROUP_EXISTS}, 400

    name = htmlentities.encode(name)
    if not correct_hex_number(color):
        return {"error": Messages.INVALID_HEX}, 400

    new_group = Groups(name=name, color=color)
    db.session.add(new_group)
    db.session.commit()

    return {"ok": Messages.GROUP_CREATED}
Example #9
0
import htmlentities

htmlentities.encode('<') # returns "&lt"
 def test_should_encode_basic_entities(self):
     self.assertEqual('&amp;', htmlentities.encode('&'))
     self.assertEqual('&quot;', htmlentities.encode('"'))
     self.assertEqual('&lt;', htmlentities.encode('<'))
 def test_should_encode_utf8_accents(self):
     self.assertEqual('&eacute;', htmlentities.encode(u'é'))
     self.assertEqual('&ecirc;', htmlentities.encode(u'ê'))
Example #12
0
 def test_should_encode_basic_entities(self):
     self.assertEqual('&amp;', htmlentities.encode('&'))
     self.assertEqual('&quot;', htmlentities.encode('"'))
     self.assertEqual('&lt;', htmlentities.encode('<'))
Example #13
0
 def test_should_encode_utf8_accents(self):
     self.assertEqual('&eacute;', htmlentities.encode(u'é'))
     self.assertEqual('&ecirc;', htmlentities.encode(u'ê'))