├── .gitignore ├── LICENSE ├── README.md └── code ├── args_v_kwargs.py ├── django-signals ├── cfehome │ ├── __init__.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── manage.py ├── posts │ ├── __init__.py │ ├── admin.py │ ├── apps.py │ ├── examples.py │ ├── migrations │ │ ├── 0001_initial.py │ │ ├── 0002_blogpost_active.py │ │ └── __init__.py │ ├── models.py │ ├── tests.py │ └── views.py └── pyvenv.cfg └── integrate-airtable.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | .DS_Store 131 | bin/ 132 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Coding For Entrepreneurs 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # questions 2 | Code for answers to common questions in programming. 3 | -------------------------------------------------------------------------------- /code/args_v_kwargs.py: -------------------------------------------------------------------------------- 1 | # from https://www.youtube.com/watch?v=GdSJAZDsCZA 2 | 3 | 4 | def my_func(): 5 | print("hello world") 6 | 7 | my_func() 8 | 9 | 10 | def my_func(): 11 | print("hello world") 12 | 13 | my_func("abc") 14 | 15 | 16 | 17 | def my_func(*args): 18 | print("hello world", args) 19 | 20 | my_func("abc", "abc", 123, "abc",) 21 | 22 | 23 | def my_func(key=None, *args): 24 | print("hello world", args) 25 | 26 | my_func("abc", "abc", 123, "abc", key=123) 27 | 28 | 29 | 30 | def my_func(*args, **kwargs): 31 | print("hello world", args, kwargs) 32 | 33 | my_func("abc", "abc", 123, "abc", key=123, abc=123) 34 | 35 | 36 | def my_func(abc=None, *args, **kwargs): 37 | print("hello world", args, kwargs) 38 | 39 | my_func("abc", abc=123) 40 | 41 | 42 | def my_func(abc=None, *args, **kwargs): 43 | print("hello world", args, kwargs) 44 | 45 | my_func(abc=123) 46 | 47 | 48 | def my_func(abc=None, *args, **kwargs): 49 | print("hello world", args, kwargs) 50 | 51 | my_func(abc=123, "abc") 52 | 53 | 54 | def my_func(arg_1, *args, **kwargs): 55 | print("hello world", args, kwargs) 56 | 57 | my_func(abc=123, "abc") 58 | 59 | 60 | def my_func(*args, **kwargs): 61 | print("hello world", args, kwargs) 62 | 63 | my_func("abc", abc=123) 64 | 65 | 66 | def my_random_django_view(request, **kwargs): 67 | print(kwargs) 68 | # Product.objects.get(id=kwargs.get('id')) 69 | 70 | # path('my-product/:id') 71 | my_random_django_view("request", id='some_id') 72 | -------------------------------------------------------------------------------- /code/django-signals/cfehome/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codingforentrepreneurs/questions/864d24c9e6a264c1f5e56d22e33ce11245b175ec/code/django-signals/cfehome/__init__.py -------------------------------------------------------------------------------- /code/django-signals/cfehome/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for cfehome project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cfehome.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /code/django-signals/cfehome/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for cfehome project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.1.5. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.1/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'ubqcd3t0kq-cdb5b7rkk*-_hcmd=#@)qra&y=w7!d3=v)kpr#$' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'posts', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'cfehome.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'cfehome.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/3.1/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/3.1/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | -------------------------------------------------------------------------------- /code/django-signals/cfehome/urls.py: -------------------------------------------------------------------------------- 1 | """cfehome URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.1/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /code/django-signals/cfehome/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for cfehome project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cfehome.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /code/django-signals/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'cfehome.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /code/django-signals/posts/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codingforentrepreneurs/questions/864d24c9e6a264c1f5e56d22e33ce11245b175ec/code/django-signals/posts/__init__.py -------------------------------------------------------------------------------- /code/django-signals/posts/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | from .models import BlogPost 5 | 6 | admin.site.register(BlogPost) -------------------------------------------------------------------------------- /code/django-signals/posts/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class PostsConfig(AppConfig): 5 | name = 'posts' 6 | -------------------------------------------------------------------------------- /code/django-signals/posts/examples.py: -------------------------------------------------------------------------------- 1 | from django.contrib.auth import get_user_model 2 | 3 | User = get_user_model() 4 | 5 | # pre_save -> instance -> my_handler 6 | instance = User.objects.create() # save User data in the database 7 | # post_save -> instance, created=True -> my_handler 8 | 9 | # pre_save -> instance -> my_handler 10 | instance.save() 11 | # post_save -> instance, created=False -> my_handler 12 | 13 | # pre_delete -> instance -> my_handler 14 | instance.delete() 15 | # post_delete -> instance -> my_handler -------------------------------------------------------------------------------- /code/django-signals/posts/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.5 on 2021-01-27 18:16 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | initial = True 10 | 11 | dependencies = [ 12 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 13 | ] 14 | 15 | operations = [ 16 | migrations.CreateModel( 17 | name='BlogPost', 18 | fields=[ 19 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 20 | ('title', models.CharField(max_length=120)), 21 | ('slug', models.SlugField(blank=True, null=True)), 22 | ('notify_users', models.BooleanField(default=False)), 23 | ('notify_users_timestamp', models.DateTimeField(blank=True, null=True)), 24 | ('liked', models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL)), 25 | ], 26 | ), 27 | ] 28 | -------------------------------------------------------------------------------- /code/django-signals/posts/migrations/0002_blogpost_active.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.5 on 2021-01-27 18:32 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('posts', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='blogpost', 15 | name='active', 16 | field=models.BooleanField(default=True), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /code/django-signals/posts/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codingforentrepreneurs/questions/864d24c9e6a264c1f5e56d22e33ce11245b175ec/code/django-signals/posts/migrations/__init__.py -------------------------------------------------------------------------------- /code/django-signals/posts/models.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.db import models 3 | from django.utils import timezone 4 | from django.utils.text import slugify 5 | 6 | # signals imports 7 | from django.dispatch import receiver 8 | from django.db.models.signals import ( 9 | pre_save, 10 | post_save, 11 | pre_delete, 12 | post_delete, 13 | m2m_changed, 14 | ) 15 | 16 | User = settings.AUTH_USER_MODEL 17 | 18 | 19 | 20 | @receiver(pre_save, sender=User) 21 | def user_pre_save_receiver(sender, instance, *args, **kwargs): 22 | """ 23 | before saved in the database 24 | """ 25 | print(instance.username, instance.id) # None 26 | # trigger pre_save 27 | # DONT DO THIS -> instance.save() 28 | # trigger post_save 29 | 30 | # pre_save.connect(user_created_handler, sender=User) 31 | 32 | 33 | @receiver(post_save, sender=User) 34 | def user_post_save_receiver(sender, instance, created, *args, **kwargs): 35 | """ 36 | after saved in the database 37 | """ 38 | if created: 39 | print("Send email to", instance.username) 40 | # trigger pre_save 41 | # instance.save() 42 | # trigger post_save 43 | else: 44 | print(instance.username, "was just saved") 45 | 46 | # post_save.connect(user_created_handler, sender=User) 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | class BlogPost(models.Model): 57 | title = models.CharField(max_length=120) 58 | slug = models.SlugField(blank=True, null=True) 59 | liked = models.ManyToManyField(User, blank=True) 60 | notify_users = models.BooleanField(default=False) 61 | notify_users_timestamp = models.DateTimeField(blank=True, null=True, auto_now_add=False) 62 | active = models.BooleanField(default=True) 63 | 64 | 65 | @receiver(pre_save, sender=BlogPost) 66 | def blog_post_pre_save(sender, instance, *args, **kwargs): 67 | if not instance.slug: 68 | instance.slug = slugify(instance.title) 69 | 70 | @receiver(post_save, sender=BlogPost) 71 | def blog_post_post_save(sender, instance, created, *args, **kwargs): 72 | if instance.notify_users: 73 | print("notify users") 74 | instance.notify_users = False 75 | # celery worker task -> offload -> Time & Tasks 2 cfe.sh 76 | instance.notify_users_timestamp = timezone.now() 77 | instance.save() 78 | 79 | 80 | @receiver(pre_delete, sender=BlogPost) 81 | def blog_post_pre_delete(sender, instance, *args, **kwargs): 82 | # move or make a backup of this data 83 | print(f"{instance.id} will be removed") 84 | 85 | # pre_delete.connect(blog_post_pre_delete, sender=BlogPost) 86 | 87 | 88 | @receiver(post_delete, sender=BlogPost) 89 | def blog_post_post_delete(sender, instance, *args, **kwargs): 90 | # celery worker task -> offload -> Time & Tasks 2 cfe.sh 91 | print(f"{instance.id} has removed") 92 | 93 | 94 | # post_delete.connect(blog_post_post_delete, sender=BlogPost) 95 | 96 | 97 | @receiver(m2m_changed, sender=BlogPost.liked.through) 98 | def blog_post_liked_changed(sender, instance, action, *args, **kwargs): 99 | # print(args, kwargs) 100 | # print(action) 101 | if action == 'pre_add': 102 | print("was added") 103 | qs = kwargs.get("model").objects.filter(pk__in=kwargs.get('pk_set')) 104 | print(qs.count()) 105 | -------------------------------------------------------------------------------- /code/django-signals/posts/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /code/django-signals/posts/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /code/django-signals/pyvenv.cfg: -------------------------------------------------------------------------------- 1 | home = /Library/Frameworks/Python.framework/Versions/3.8/bin 2 | include-system-site-packages = false 3 | version = 3.8.2 4 | -------------------------------------------------------------------------------- /code/integrate-airtable.py: -------------------------------------------------------------------------------- 1 | """ 2 | Installations: 3 | 4 | python -m pip install requests python-dotenv 5 | 6 | Create a .env file with: 7 | 8 | AIRTABLE_BASE_ID='your_base_id' 9 | AIRTABLE_API_KEY='your_api_key' 10 | AIRTABLE_TABLE_NAME='your_table_name' 11 | 12 | The AIRTABLE_API_KEY can be generated on: https://airtable.com/account 13 | """ 14 | 15 | import os 16 | import requests 17 | from dotenv import load_dotenv 18 | load_dotenv() 19 | 20 | 21 | AIRTABLE_BASE_ID=os.environ.get("AIRTABLE_BASE_ID") 22 | AIRTABLE_API_KEY=os.environ.get("AIRTABLE_API_KEY") 23 | AIRTABLE_TABLE_NAME=os.environ.get("AIRTABLE_TABLE_NAME") 24 | 25 | endpoint=f'https://api.airtable.com/v0/{AIRTABLE_BASE_ID}/{AIRTABLE_TABLE_NAME}' 26 | 27 | # python requests headers 28 | # headers = { 29 | # "Authorization": f"Bearer {AIRTABLE_API_KEY}", 30 | # "Content-Type": "application/json" 31 | # } 32 | 33 | # data = { 34 | # "records": [ 35 | # { 36 | # "fields": { 37 | # "name": "Justin", 38 | # "Email": "abc@notreal.com\n" 39 | # } 40 | # }, 41 | # { 42 | # "fields": { 43 | # "name": "Justin", 44 | # "Email": "abc@notreal.com\n" 45 | # } 46 | # } 47 | # ] 48 | # } 49 | 50 | # # http methods? 51 | # # what is the method for "create" -> HTTP Method POST 52 | 53 | 54 | # r = requests.post(endpoint, json=data, headers=headers) 55 | # print(r.status_code) 56 | 57 | 58 | def add_to_airtable(email=None, name=""): 59 | if email is None: 60 | return 61 | headers = { 62 | "Authorization": f"Bearer {AIRTABLE_API_KEY}", 63 | "Content-Type": "application/json" 64 | } 65 | data = { 66 | "records": [ 67 | { 68 | "fields": { 69 | "name": name, 70 | "email": email 71 | } 72 | } 73 | ] 74 | } 75 | r = requests.post(endpoint, json=data, headers=headers) 76 | return r.status_code == 200 77 | 78 | 79 | # email = input("What is your email?\n") 80 | # name = input("What is your name?\n") 81 | 82 | # add_to_airtable(email, name=name) 83 | 84 | add_to_airtable('abc-123fadsf@gmail.com', name="Not real") 85 | --------------------------------------------------------------------------------