This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| api_key = "sk-..." | |
| resp = requests.get("https://api.openai.com/v1/models", headers={"Authorization": f"Bearer {api_key}"}) | |
| print(resp.json()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # pip install requests requests-cache | |
| import requests | |
| import requests_cache | |
| from datetime import timedelta | |
| # Enable a transparent on-disk HTTP cache (GET only) | |
| requests_cache.install_cache( | |
| cache_name=".http_cache", # folder/files on disk | |
| expire_after=timedelta(hours=6), # global TTL | |
| allowable_methods=("GET",), # don't cache POST/PUT by default |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| import sys | |
| import textwrap | |
| from lxml.html import document_fromstring | |
| from optparse import OptionParser | |
| from urllib.parse import urlparse | |
| class FolhaSpParser(object): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Inspired by https://en.wikibooks.org/wiki/Cookbook and others. | |
| cookbook = { | |
| 'risotto': {'name': 'Risotto', 'category': 'Rice recipes', 'url': 'https://en.wikibooks.org/wiki/Cookbook:Risotto',}, | |
| 'crepe': {'name': 'Crêpe', 'category': 'Breakfast recipes', 'url': 'https://en.wikibooks.org/wiki/Cookbook:Cr%C3%AApe',}, | |
| 'bouillabaisse': {'name': 'Bouillabaisse', 'category': 'French recipes', 'url': 'https://en.wikibooks.org/wiki/Cookbook:Bouillabaisse',}, | |
| } | |
| # Iterate by key |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Requires the installation of "faker": pip install faker | |
| from faker import Faker | |
| fake = Faker() | |
| for _ in range(0, 20): | |
| p = {'firstname': fake.last_name(), 'lastname': fake.last_name()} | |
| print(p) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # We use the standard module "operator" | |
| import operator | |
| # A dictionary | |
| C = {4:'abc', 2:'gfc', 5:'afe', 3:'fgh'} | |
| # Sort by the dictionary keys ; produces a list of the items tuples. | |
| C1 = sorted(C.items(), key=operator.itemgetter(0)) | |
| print(C1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from Products.Five.browser import BrowserView | |
| from plone import api | |
| class CustomRegisterUserView(BrowserView): | |
| """View to create a new user 'jdoe'. | |
| """ | |
| def __call__(self): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0"?> | |
| <object name="Document" meta_type="Dexterity FTI" i18n:domain="plone" | |
| xmlns:i18n="http://xml.zope.org/namespaces/i18n"> | |
| <property name="title" i18n:translate="">Page</property> | |
| <property name="behaviors"> | |
| <element value="plone.app.content.interfaces.INameFromTitle"/> | |
| <element value="plone.app.dexterity.behaviors.discussion.IAllowDiscussion"/> | |
| <element value="plone.app.dexterity.behaviors.exclfromnav.IExcludeFromNavigation"/> | |
| <element value="plone.app.dexterity.behaviors.metadata.IDublinCore"/> |