예제 #1
0
#from django.db import models
import contentful
from reinertsen_web.settings import SPACE_ID, ACCESS_TOKEN, ENVIRONMENT
# Create your models here.

client = contentful.Client(space_id=SPACE_ID,
                           access_token=ACCESS_TOKEN,
                           environment=ENVIRONMENT)
예제 #2
0
import os
import contentful
#from django.db import models

# Create your models here.

client = contentful.Client(
    os.environ.get('CTF_SPACE_ID', '1v7zodclvrzr'),
    os.environ.get(
        'CTF_DELIVERY_KEY',
        'f51a25a16c7279d7803228071218b1250c33d2fef1fb5a5e000e4160648875f6'))
예제 #3
0
import contentful
from flask_paginate import Pagination, get_page_parameter
from flask import render_template, request
from decouple import config

########## CONTENTFUL ############
SPACE_ID = config('SPACE_ID')
ACCESS_TOKEN = config('ACCESS_TOKEN')
client = contentful.Client(SPACE_ID, ACCESS_TOKEN)
########## CONTENTFUL ############

PRODUCT_LIMIT = 36


class Products:
    def search_product(self, search_query, search_form, skip_num):
        products = client.entries({
            'limit': PRODUCT_LIMIT,
            'content_type': 'samAndCoProducts',
            'skip': skip_num,
            'fields.title[match]': search_query
        })
        page = request.args.get(get_page_parameter(), type=int, default=1)
        pagination = Pagination(show_single_page=True,
                                page=page,
                                per_page=36,
                                total=products.total,
                                search=False,
                                record_name='products')

        return render_template('store.html',
예제 #4
0
from dotenv import load_dotenv
import os
import contentful
import contentful_management

load_dotenv()

cc = contentful.Client(os.getenv("CONTENTFUL_SPACE_ID"),
                       os.getenv("CONTENTFUL_ACCESS_TOKEN"))
cm = contentful_management.Client(os.getenv("CONTENTFUL_PAT"))


def write_guest(name, description=None):
    entry = cm.entries(os.getenv("CONTENTFUL_SPACE_ID"),
                       os.getenv("CONTENTFUL_ENVIRONMENT")).create(
                           None, {
                               "content_type_id": "guest",
                               "fields": {
                                   "name": {
                                       "en-US": name
                                   },
                                   "description": {
                                       "en-US": description
                                   }
                               }
                           })
    return entry


def write_episode(title,
                  number=None,
예제 #5
0
"""Iot Site Builder app."""
import os
from flask import Flask, render_template
import contentful
from dotenv import load_dotenv

load_dotenv()

SPACE_ID = os.getenv('SPACE_ID')
DELIVERY_API_KEY = os.getenv('DELIVERY_API_KEY')

CLIENT = contentful.Client(
    SPACE_ID,
    DELIVERY_API_KEY)

APP = Flask(__name__)


# def format_datetime(value):
#     """Format date time object using jinja filters"""
#     return value.strftime('%B %-d, %Y')


# APP.jinja_env.filters['datetime'] = format_datetime


@APP.route('/')
@APP.route('/home')
def index():
    """index route. Gathers page from contentful and builds it."""
    page = CLIENT.entries({'content_type': 'page', 'include': 10})
예제 #6
0
from flask import Flask, render_template, url_for, abort
from flaskext.markdown import Markdown
import contentful
from dotenv import load_dotenv
import os

load_dotenv()
SPACE_ID = os.environ.get("SPACE_ID")
DELIVERY_API_KEY = os.environ.get("DELIVERY_API_KEY")
API_URL = os.environ.get("API_URL")

client = contentful.Client(SPACE_ID, DELIVERY_API_KEY, API_URL)

app = Flask(__name__)
Markdown(app)


def format_datetime(value):
    """Format date time object using jinja filters"""
    return value.strftime("%B %-d, %Y")


app.jinja_env.filters["datetime"] = format_datetime


@app.route("/")
@app.route("/home")
def index():
    """index route. Gathers information from contentful and renders page"""
    shows = client.entries({
        "content_type": "show",
예제 #7
0
# from celery import Celery
# from elasticsearch import Elasticsearch, Urllib3HttpConnection
# import certifi

app = Flask(__name__, static_folder='../build')

app.config.from_object('config.environment_default')
try:
    app.config.from_object('config.environment_dev')
except ImportError:
    pass

app.mongo = PyMongo(app)
app.caches = {}

app.contentful = contentful.Client(app.config['CONTENTFUL_SPACE'],
                                   app.config['CONTENTFUL_ACCESS'])

# app.search = Elasticsearch(
# 	app.config['ELASTICSEARCH_HOST'].split(','),
# 	connection_class=Urllib3HttpConnection,
# 	http_auth=(app.config['ELASTICSEARCH_USER'], app.config['ELASTICSEARCH_PASSWORD']),
# 	use_ssl=True,
# 	verify_certs=True,
# 	ca_certs=certifi.where()
# )

# celery = Celery(app.import_name, broker=app.config['CELERY_BROKER_URL'])
# celery.config_from_object(app.config)

# from core.tasks.execute import execute_task
# from core.tasks.trigger import trigger_tasks
예제 #8
0
import contentful
from pygit2 import Repository

branch_name = Repository('.').head.shorthand

client = contentful.Client('vv5raolukrc9',
                           'R_uqYKE6N7u-VzAi0bGiZaE0F7CD1n-t_uN9vwvRYOU',
                           environment=branch_name)

entry = client.entry('15jwOBqpxqSAOy2eOO4S0m')

print entry.name
예제 #9
0
from constants import *
import contentful
from datetime import datetime
from common_utils.error_handler import CondenastException
from serializer import PlaceSerializer, FeedSerializer, ContributorSerializer
from django.conf import settings

# setting contentful client
client = contentful.Client(settings.SPACE_ID, settings.ACCESS_KEY)
# getting database object
db = settings.DB
# Method takes input and update or edit a place based on placeId


class AddOrEditPlace(object):
    place_serializer = PlaceSerializer

    @classmethod
    def add_edit_place(cls, input_request, place_id):

        # check if object exist, if yes update
        place = db.Places.find({'place_id': place_id})
        if place.count() > 0:
            place = place[0]
            for key, value in input_request.iteritems():
                if key == 'location':
                    location = value.get('en-US')
                    place_location = []
                    place_location.insert(0, location.get('lon'))
                    place_location.insert(1, location.get('lat'))
                    place['location'] = place_location
예제 #10
0
import contentful

client = contentful.Client(
    "jokk403r56yp",  # This is the space ID. A space is like a project folder in Contentful terms
    "8b9ddca4bfaa8e3f68520e1211700c6b0fbee29459e7d5b5c776626a3230e8d0",  # This is the access token for this space. Normally you get both ID and the token in the Contentful web app
)


def main(event, context):
    entry = client.entry("3hPCvDC6URrqtst7zNMkqI")
    slides = entry.slides
    markdown = ""
    for slide in slides:
        if markdown != "":
            markdown += "\n\n\n"

        try:
            markdown += "".join(["# ", slide.title, "\n"])
        except AttributeError:
            print("Empty Title")

        try:
            markdown += "".join(["## ", slide.subtitle, "\n"])
        except AttributeError:
            print("Empty Subtitle")

        try:
            markdown += "".join([slide.body, "\n"])
        except AttributeError:
            print("Empty Body")