diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4821b77 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +venv +.env +config.py \ No newline at end of file diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..9038823 Binary files /dev/null and b/db.sqlite3 differ diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..dd1394a --- /dev/null +++ b/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'twittermachine.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bc00fe8 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,24 @@ +asgiref==3.5.2 +certifi==2022.9.24 +charset-normalizer==2.1.1 +config==0.5.1 +Django==4.1.3 +et-xmlfile==1.1.0 +idna==3.4 +numpy==1.23.5 +oauthlib==3.2.2 +openai==0.25.0 +openpyxl==3.0.10 +pandas==1.5.2 +pandas-stubs==1.5.2.221124 +python-dateutil==2.8.2 +pytz==2022.6 +requests==2.28.1 +requests-oauthlib==1.3.1 +six==1.16.0 +sqlparse==0.4.3 +tqdm==4.64.1 +tweepy==4.12.1 +types-pytz==2022.6.0.1 +typing_extensions==4.4.0 +urllib3==1.26.13 diff --git a/themachine/__init__.py b/themachine/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/themachine/__pycache__/__init__.cpython-310.pyc b/themachine/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..f2b19d0 Binary files /dev/null and b/themachine/__pycache__/__init__.cpython-310.pyc differ diff --git a/themachine/__pycache__/admin.cpython-310.pyc b/themachine/__pycache__/admin.cpython-310.pyc new file mode 100644 index 0000000..e187b02 Binary files /dev/null and b/themachine/__pycache__/admin.cpython-310.pyc differ diff --git a/themachine/__pycache__/apps.cpython-310.pyc b/themachine/__pycache__/apps.cpython-310.pyc new file mode 100644 index 0000000..08939a7 Binary files /dev/null and b/themachine/__pycache__/apps.cpython-310.pyc differ diff --git a/themachine/__pycache__/models.cpython-310.pyc b/themachine/__pycache__/models.cpython-310.pyc new file mode 100644 index 0000000..4778611 Binary files /dev/null and b/themachine/__pycache__/models.cpython-310.pyc differ diff --git a/themachine/__pycache__/tests.cpython-310.pyc b/themachine/__pycache__/tests.cpython-310.pyc new file mode 100644 index 0000000..f60a976 Binary files /dev/null and b/themachine/__pycache__/tests.cpython-310.pyc differ diff --git a/themachine/__pycache__/urls.cpython-310.pyc b/themachine/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..8eeaeb3 Binary files /dev/null and b/themachine/__pycache__/urls.cpython-310.pyc differ diff --git a/themachine/__pycache__/utils.cpython-310.pyc b/themachine/__pycache__/utils.cpython-310.pyc new file mode 100644 index 0000000..5bf9afe Binary files /dev/null and b/themachine/__pycache__/utils.cpython-310.pyc differ diff --git a/themachine/__pycache__/views.cpython-310.pyc b/themachine/__pycache__/views.cpython-310.pyc new file mode 100644 index 0000000..c31af9f Binary files /dev/null and b/themachine/__pycache__/views.cpython-310.pyc differ diff --git a/themachine/admin.py b/themachine/admin.py new file mode 100644 index 0000000..0ea5773 --- /dev/null +++ b/themachine/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import TextBlock +# Register your models here. + + +admin.site.register(TextBlock) diff --git a/themachine/apps.py b/themachine/apps.py new file mode 100644 index 0000000..16af23a --- /dev/null +++ b/themachine/apps.py @@ -0,0 +1,7 @@ +from django.apps import AppConfig + + +class ThemachineConfig(AppConfig): + default_auto_field = "django.db.models.BigAutoField" + name = "themachine" + diff --git a/themachine/migrations/0001_initial.py b/themachine/migrations/0001_initial.py new file mode 100644 index 0000000..ed34620 --- /dev/null +++ b/themachine/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# Generated by Django 4.1.3 on 2022-12-03 09:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [] + + operations = [ + migrations.CreateModel( + name="TextBlock", + fields=[ + ( + "id", + models.BigAutoField( + auto_created=True, + primary_key=True, + serialize=False, + verbose_name="ID", + ), + ), + ("text", models.TextField(blank=True)), + ("tweet", models.TextField(blank=True)), + ], + ), + ] diff --git a/themachine/migrations/__init__.py b/themachine/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/themachine/migrations/__pycache__/0001_initial.cpython-310.pyc b/themachine/migrations/__pycache__/0001_initial.cpython-310.pyc new file mode 100644 index 0000000..da50560 Binary files /dev/null and b/themachine/migrations/__pycache__/0001_initial.cpython-310.pyc differ diff --git a/themachine/migrations/__pycache__/__init__.cpython-310.pyc b/themachine/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..59bb7ab Binary files /dev/null and b/themachine/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/themachine/models.py b/themachine/models.py new file mode 100644 index 0000000..6332c1e --- /dev/null +++ b/themachine/models.py @@ -0,0 +1,22 @@ +from django.db import models +from .utils import create_tweet + +# Create your models here. + +class TextBlock(models.Model): + text = models.TextField(blank=True) + tweet = models.TextField(blank=True) + + def save(self) -> None: + prompt = {} + prompt["hashtag"] = "#thethoughtmachine" + prompt["text"] = "Write an engaging, controversial tweet that has a high probability of getting viral or trending using these words:" + self.text + thething = create_tweet(prompt) + self.tweet = thething + print(thething) + return super().save() + + + + def __str__(self): + return f"{self.text} {self.tweet}" \ No newline at end of file diff --git a/themachine/templates/main.html b/themachine/templates/main.html new file mode 100644 index 0000000..9c18b2f --- /dev/null +++ b/themachine/templates/main.html @@ -0,0 +1,10 @@ + + + + + + + Document + + +{% block content %}{% endblock %} \ No newline at end of file diff --git a/themachine/templates/themachine/home.html b/themachine/templates/themachine/home.html new file mode 100644 index 0000000..13bdf04 --- /dev/null +++ b/themachine/templates/themachine/home.html @@ -0,0 +1,42 @@ +{% extends 'main.html' %} +{% block content %} + +
+

Hello!

+

This is the Thought Machine!

+
+

This is a tool to create tweets using ai for you! I mean, this is the future right? Why would you think of a tweet if ai can do a better, more engagable tweet than yourself?

+

So stop thinking and start zombie-tweeting!

+
+ Create Zombie Tweet + {% comment %} {% endcomment %} +
+
+
+
+ + + + + + + + + + {% for textblock in object_list %} + + + + + + + + {% endfor %} +
#TextTweet
{{ forloop.counter }}{{ textblock.text }}{{ textblock.tweet }}
+
+
+
+ + +{% endblock %} + diff --git a/themachine/templates/themachine/textblock_form.html b/themachine/templates/themachine/textblock_form.html new file mode 100644 index 0000000..1d451b6 --- /dev/null +++ b/themachine/templates/themachine/textblock_form.html @@ -0,0 +1,17 @@ +{% extends 'main.html' %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block content %} +
+
+

Twitter Machine

+
Write some ideas keyword so the machine can create a tweet based on that!
+ {% csrf_token %} + {{ form|crispy }} +
+ +
+
+
+{% endblock %} diff --git a/themachine/tests.py b/themachine/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/themachine/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/themachine/urls.py b/themachine/urls.py new file mode 100644 index 0000000..bb63644 --- /dev/null +++ b/themachine/urls.py @@ -0,0 +1,12 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path( + "", views.HomeView.as_view(), name="home" + ), + path("create-tweet/", views.TextBlockCreateView.as_view(), name="create-tweet" + ), + +] \ No newline at end of file diff --git a/themachine/utils.py b/themachine/utils.py new file mode 100644 index 0000000..28ae590 --- /dev/null +++ b/themachine/utils.py @@ -0,0 +1,26 @@ +import random, config + +import openai, tweepy + +#OpenAI API credentials +openai.api_key =config.open_ai_key + +print("Connected to Twitter") + + +def create_tweet(prompt): + text = prompt["text"] + hashtags = prompt["hashtag"] + + response = openai.Completion.create( + engine="text-davinci-001", + prompt=text, + max_tokens=50, + ) + + tweet = response.choices[0].text + tweet = tweet + " " + hashtags + " " + "#ai #openai #gpt3" + return tweet + +# tweet = create_tweet() +# api.update_status(tweet) \ No newline at end of file diff --git a/themachine/views.py b/themachine/views.py new file mode 100644 index 0000000..f8b5a9c --- /dev/null +++ b/themachine/views.py @@ -0,0 +1,27 @@ +from django.shortcuts import render +from django.http import HttpResponse +from django.urls import reverse +from django.views.generic import TemplateView, CreateView, ListView + +from .models import TextBlock + + +# Create your views here. +class TextBlockCreateView(CreateView): + model = TextBlock + fields = ['text'] + template_name = "themachine/textblock_form.html" + + def get_success_url(self): + return reverse("home") + + + +class HomeView(ListView): + template_name = "themachine/home.html" + model = TextBlock + queryset = TextBlock.objects.all().order_by('-id')[:10] + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + return context + diff --git a/twittermachine/__init__.py b/twittermachine/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/twittermachine/__pycache__/__init__.cpython-310.pyc b/twittermachine/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000..e5d8bf2 Binary files /dev/null and b/twittermachine/__pycache__/__init__.cpython-310.pyc differ diff --git a/twittermachine/__pycache__/settings.cpython-310.pyc b/twittermachine/__pycache__/settings.cpython-310.pyc new file mode 100644 index 0000000..f608dd1 Binary files /dev/null and b/twittermachine/__pycache__/settings.cpython-310.pyc differ diff --git a/twittermachine/__pycache__/urls.cpython-310.pyc b/twittermachine/__pycache__/urls.cpython-310.pyc new file mode 100644 index 0000000..09c7dd4 Binary files /dev/null and b/twittermachine/__pycache__/urls.cpython-310.pyc differ diff --git a/twittermachine/__pycache__/wsgi.cpython-310.pyc b/twittermachine/__pycache__/wsgi.cpython-310.pyc new file mode 100644 index 0000000..cfd0ed5 Binary files /dev/null and b/twittermachine/__pycache__/wsgi.cpython-310.pyc differ diff --git a/twittermachine/asgi.py b/twittermachine/asgi.py new file mode 100644 index 0000000..747a07d --- /dev/null +++ b/twittermachine/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for twittermachine project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'twittermachine.settings') + +application = get_asgi_application() diff --git a/twittermachine/settings.py b/twittermachine/settings.py new file mode 100644 index 0000000..b4818cd --- /dev/null +++ b/twittermachine/settings.py @@ -0,0 +1,127 @@ +""" +Django settings for twittermachine project. + +Generated by 'django-admin startproject' using Django 3.2.7. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-174o%*%p!t7-w+w3qqj7gsc)^&s0nlh@0vep^8*eh&zgiz@em-' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'themachine', + 'crispy_forms', +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'twittermachine.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'twittermachine.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/twittermachine/urls.py b/twittermachine/urls.py new file mode 100644 index 0000000..8b33454 --- /dev/null +++ b/twittermachine/urls.py @@ -0,0 +1,23 @@ +"""twittermachine URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import include, path + +urlpatterns = [ + path('admin/', admin.site.urls), + path("", include("themachine.urls")) + +] diff --git a/twittermachine/wsgi.py b/twittermachine/wsgi.py new file mode 100644 index 0000000..77c03ee --- /dev/null +++ b/twittermachine/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for twittermachine project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'twittermachine.settings') + +application = get_wsgi_application()