├── README.md ├── bank ├── README.md └── bank.py ├── bitcoin ├── README.md └── bitcoin.py ├── caesar ├── README.md ├── caesar └── caesar.c ├── class ├── README.md └── class.py ├── coke ├── README.md └── coke.py ├── commerce ├── README.md ├── auctions │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-310.pyc │ │ ├── __init__.cpython-38.pyc │ │ ├── admin.cpython-310.pyc │ │ ├── admin.cpython-38.pyc │ │ ├── apps.cpython-310.pyc │ │ ├── models.cpython-310.pyc │ │ ├── models.cpython-38.pyc │ │ ├── urls.cpython-310.pyc │ │ ├── urls.cpython-38.pyc │ │ ├── views.cpython-310.pyc │ │ └── views.cpython-38.pyc │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ ├── 0001_initial.py │ │ ├── 0002_listing_user.py │ │ ├── 0003_listing_category.py │ │ ├── 0004_auto_20200713_1748.py │ │ ├── 0005_listing_winner.py │ │ ├── 0006_watchlist.py │ │ ├── 0007_listing_active.py │ │ ├── 0008_alter_user_first_name.py │ │ ├── __init__.py │ │ └── __pycache__ │ │ │ ├── 0001_initial.cpython-310.pyc │ │ │ ├── 0001_initial.cpython-38.pyc │ │ │ ├── 0002_listing_user.cpython-310.pyc │ │ │ ├── 0002_listing_user.cpython-38.pyc │ │ │ ├── 0003_listing_category.cpython-310.pyc │ │ │ ├── 0003_listing_category.cpython-38.pyc │ │ │ ├── 0003_remove_listing_user.cpython-38.pyc │ │ │ ├── 0004_auto_20200713_1747.cpython-38.pyc │ │ │ ├── 0004_auto_20200713_1748.cpython-310.pyc │ │ │ ├── 0004_auto_20200713_1748.cpython-38.pyc │ │ │ ├── 0005_listing_winner.cpython-310.pyc │ │ │ ├── 0005_listing_winner.cpython-38.pyc │ │ │ ├── 0005_remove_listing_winner.cpython-38.pyc │ │ │ ├── 0006_listing_watchlist.cpython-38.pyc │ │ │ ├── 0006_watchlist.cpython-310.pyc │ │ │ ├── 0006_watchlist.cpython-38.pyc │ │ │ ├── 0007_listing_active.cpython-310.pyc │ │ │ ├── 0007_listing_active.cpython-38.pyc │ │ │ ├── 0008_alter_user_first_name.cpython-310.pyc │ │ │ ├── __init__.cpython-310.pyc │ │ │ └── __init__.cpython-38.pyc │ ├── models.py │ ├── static │ │ └── auctions │ │ │ └── styles.css │ ├── templates │ │ └── auctions │ │ │ ├── categories.html │ │ │ ├── category_listing.html │ │ │ ├── create.html │ │ │ ├── error.html │ │ │ ├── index.html │ │ │ ├── layout.html │ │ │ ├── listing.html │ │ │ ├── login.html │ │ │ ├── register.html │ │ │ └── watchlist.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── commerce │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-310.pyc │ │ ├── __init__.cpython-38.pyc │ │ ├── settings.cpython-310.pyc │ │ ├── settings.cpython-38.pyc │ │ ├── urls.cpython-310.pyc │ │ ├── urls.cpython-38.pyc │ │ ├── wsgi.cpython-310.pyc │ │ └── wsgi.cpython-38.pyc │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 └── manage.py ├── cs50web-Network ├── db.sqlite3 ├── manage.py ├── network │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-311.pyc │ │ ├── __init__.cpython-38.pyc │ │ ├── admin.cpython-311.pyc │ │ ├── admin.cpython-38.pyc │ │ ├── apps.cpython-311.pyc │ │ ├── forms.cpython-38.pyc │ │ ├── models.cpython-311.pyc │ │ ├── models.cpython-38.pyc │ │ ├── serializers.cpython-311.pyc │ │ ├── serializers.cpython-38.pyc │ │ ├── urls.cpython-311.pyc │ │ ├── urls.cpython-38.pyc │ │ ├── views.cpython-311.pyc │ │ └── views.cpython-38.pyc │ ├── admin.py │ ├── apps.py │ ├── forms.py │ ├── migrations │ │ ├── 0001_initial.py │ │ ├── __init__.py │ │ └── __pycache__ │ │ │ ├── 0001_initial.cpython-311.pyc │ │ │ ├── 0001_initial.cpython-38.pyc │ │ │ ├── __init__.cpython-311.pyc │ │ │ └── __init__.cpython-38.pyc │ ├── models.py │ ├── serializers.py │ ├── static │ │ └── network │ │ │ ├── allposts.png │ │ │ ├── editting.png │ │ │ ├── followed.png │ │ │ ├── followinginterface.png │ │ │ ├── index.js │ │ │ ├── like0.png │ │ │ ├── liked.png │ │ │ ├── profile.png │ │ │ └── styles.css │ ├── templates │ │ └── network │ │ │ ├── index.html │ │ │ ├── layout.html │ │ │ ├── login.html │ │ │ └── register.html │ ├── tests.py │ ├── urls.py │ └── views.py └── project4 │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-311.pyc │ ├── __init__.cpython-38.pyc │ ├── settings.cpython-311.pyc │ ├── settings.cpython-38.pyc │ ├── urls.cpython-311.pyc │ ├── urls.cpython-38.pyc │ ├── wsgi.cpython-311.pyc │ └── wsgi.cpython-38.pyc │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── deep ├── README.md └── deep.py ├── dna ├── README.md ├── databases │ ├── large.csv │ └── small.csv ├── dna.py └── sequences │ ├── 1.txt │ ├── 10.txt │ ├── 11.txt │ ├── 12.txt │ ├── 13.txt │ ├── 14.txt │ ├── 15.txt │ ├── 16.txt │ ├── 17.txt │ ├── 18.txt │ ├── 19.txt │ ├── 2.txt │ ├── 20.txt │ ├── 3.txt │ ├── 4.txt │ ├── 5.txt │ ├── 6.txt │ ├── 7.txt │ ├── 8.txt │ └── 9.txt ├── einstein ├── README.md └── einstein.py ├── extensions ├── README.md └── extensions.py ├── figlet ├── README.md └── figlet.py ├── final_project ├── README.md ├── phonebook.db ├── project.py ├── responce.py └── test_project.py ├── font ├── README.md └── font.py ├── fuel ├── README.md ├── feul.py └── fuel.py ├── hello └── hello.c ├── indoor ├── README.md └── indoor.py ├── jar ├── README.md ├── __pycache__ │ ├── jar.cpython-310.pyc │ └── test_jar.cpython-310-pytest-7.1.2.pyc ├── jar.py └── test_jar.py ├── lines ├── README.md └── lines.py ├── logs ├── mail ├── README.md ├── db.sqlite3 ├── mail │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-311.pyc │ │ ├── __init__.cpython-36.pyc │ │ ├── admin.cpython-311.pyc │ │ ├── admin.cpython-36.pyc │ │ ├── apps.cpython-311.pyc │ │ ├── models.cpython-311.pyc │ │ ├── models.cpython-36.pyc │ │ ├── urls.cpython-311.pyc │ │ ├── urls.cpython-36.pyc │ │ ├── views.cpython-311.pyc │ │ └── views.cpython-36.pyc │ ├── admin.py │ ├── apps.py │ ├── migrations │ │ ├── 0001_initial.py │ │ ├── 0002_alter_user_first_name.py │ │ ├── __init__.py │ │ └── __pycache__ │ │ │ ├── 0001_initial.cpython-311.pyc │ │ │ ├── 0001_initial.cpython-36.pyc │ │ │ ├── 0002_alter_user_first_name.cpython-311.pyc │ │ │ ├── __init__.cpython-311.pyc │ │ │ └── __init__.cpython-36.pyc │ ├── models.py │ ├── static │ │ └── mail │ │ │ ├── Todo │ │ │ ├── inbox.js │ │ │ └── styles.css │ ├── templates │ │ └── mail │ │ │ ├── inbox.html │ │ │ ├── layout.html │ │ │ ├── login.html │ │ │ └── register.html │ ├── tests.py │ ├── urls.py │ └── views.py ├── manage.py └── project3 │ ├── __init__.py │ ├── __pycache__ │ ├── __init__.cpython-311.pyc │ ├── __init__.cpython-36.pyc │ ├── settings.cpython-311.pyc │ ├── settings.cpython-36.pyc │ ├── urls.cpython-311.pyc │ ├── urls.cpython-36.pyc │ ├── wsgi.cpython-311.pyc │ └── wsgi.cpython-36.pyc │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── mario-more ├── README.md ├── mario └── mario.c ├── outdated ├── README.md └── outdated.py ├── plates ├── README.md └── plates.py ├── plurality ├── README.md ├── plurality └── plurality.c ├── project ├── README.md ├── app.py ├── messenger.db └── templates │ ├── error.html │ ├── index.html │ └── login.html ├── readability ├── README.md └── readability.py ├── runoff ├── README.md ├── runoff └── runoff.c ├── scourgify ├── README.md └── scourgify.py ├── search ├── README.md ├── advance.html ├── image.html ├── index.html └── style.css ├── seasons ├── README.md ├── seasons.py └── test_seasons.py ├── sentimental-mario-more ├── README.md └── mario.py ├── shirtificate ├── README.md ├── shirtificate.pdf ├── shirtificate.png └── shirtificate.py ├── speller ├── Makefile ├── README.md ├── dictionaries │ ├── large │ └── small ├── dictionary.c ├── dictionary.h ├── dictionary.o ├── keys │ ├── aca.txt │ ├── austen.txt │ ├── birdman.txt │ ├── burnett.txt │ ├── carroll.txt │ ├── cat.txt │ ├── constitution.txt │ ├── federalist.txt │ ├── frankenstein.txt │ ├── grimm.txt │ ├── her.txt │ ├── holmes.txt │ ├── homer.txt │ ├── lalaland.txt │ ├── mansfield.txt │ ├── pneumonoultramicroscopicsilicovolcanoconiosis.txt │ ├── revenant.txt │ ├── rinehart.txt │ ├── shakespeare.txt │ ├── stein.txt │ ├── stoker.txt │ ├── surgery.txt │ ├── tolstoy.txt │ ├── wells.txt │ ├── whittier.txt │ ├── wordsworth.txt │ ├── xueqin1.txt │ └── xueqin2.txt ├── speller ├── speller.c ├── speller.o ├── speller50 └── texts │ ├── aca.txt │ ├── austen.txt │ ├── birdman.txt │ ├── burnett.txt │ ├── carroll.txt │ ├── cat.txt │ ├── constitution.txt │ ├── federalist.txt │ ├── frankenstein.txt │ ├── grimm.txt │ ├── her.txt │ ├── holmes.txt │ ├── homer.txt │ ├── lalaland.txt │ ├── mansfield.txt │ ├── pneumonoultramicroscopicsilicovolcanoconiosis.txt │ ├── revenant.txt │ ├── rinehart.txt │ ├── shakespeare.txt │ ├── stein.txt │ ├── stoker.txt │ ├── surgery.txt │ ├── tolstoy.txt │ ├── wells.txt │ ├── whittier.txt │ ├── wordsworth.txt │ ├── xueqin1.txt │ └── xueqin2.txt ├── taqueria ├── README.md └── taqueria.py ├── test_bank ├── README.md ├── bank.py └── test_bank.py ├── test_fuel ├── README.md ├── fuel.py └── test_fuel.py ├── test_twttr ├── README.md ├── test_twttr.py └── twttr.py ├── tip ├── README.md └── tip.py ├── trivia ├── README.md ├── index.html └── styles.css ├── um ├── README.md ├── test_um.py └── um.py ├── watch ├── README.md ├── test_watch.py └── watch.py └── world-cup ├── .~c9_invoke_nsYYx8.py ├── 2018m.csv ├── 2019w.csv └── tournament.py /README.md: -------------------------------------------------------------------------------- 1 | # Cs50 Intro to computer Science 2 | ## Psets for CS50X, CS50P, CS50 WEB, CS50AI 3 | 4 | ## Disclaimer 5 | This is only for academical purposes 6 | 7 | ## Assignments for Harvard cs50 courses 2022 8 | 9 | * Hello - c 10 | * Caesar - c 11 | * plurality - c 12 | * grocery - python 13 | * jar - python 14 | * lines - python 15 | * outdated - python 16 | * seasons - python 17 | * shirtificate - pythons 18 | * speller - c 19 | * mario-more - c 20 | * trivia - html, css, javascript 21 | * world cup - python 22 | * speller - c 23 | * test_ - python 24 | * Cs50web-Network - Python, Django, Javascript 25 | * deep - python 26 | * einstein - python 27 | * extensions - python 28 | * font - python 29 | * coke - python 30 | * figlet - python 31 | * tip - python 32 | * um - python 33 | * mail - python-django 34 | * taqueria - python 35 | * capstone - python Django 36 | --- 37 | -------------------------------------------------------------------------------- /bank/README.md: -------------------------------------------------------------------------------- 1 | # python file to check greeting 2 | * Respond to users greeting depending on choice of words 3 | 4 | -------------------------------------------------------------------------------- /bank/bank.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | greeting = input("Greeting: ").lower() 3 | print(f"${value(greeting)}") 4 | 5 | def value(greeting): 6 | if "hello" in greeting.lower(): 7 | return 0 8 | 9 | elif greeting[0].lower() == "h": 10 | return 20 11 | 12 | else: 13 | return 100 14 | 15 | if __name__ == "__main__": 16 | main() -------------------------------------------------------------------------------- /bitcoin/README.md: -------------------------------------------------------------------------------- 1 | # python file to Check live prices of Bitcoin -------------------------------------------------------------------------------- /bitcoin/bitcoin.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import json 3 | import sys 4 | import locale 5 | 6 | locale.setlocale(locale.LC_ALL, 'en_US') 7 | 8 | amount = 0 9 | 10 | def intWithCommas(x): 11 | if type(x) not in [type(0), type(0)]: 12 | raise TypeError("Parameter must be an integer.") 13 | if x < 0: 14 | return '-' + intWithCommas(-x) 15 | result = '' 16 | while x >= 1000: 17 | x, r = divmod(x, 1000) 18 | result = ",%03d%s" % (r, result) 19 | return "%d%s" % (x, result) 20 | 21 | if len(sys.argv) < 2: 22 | sys.exit("Missing commannd line arguement.") 23 | elif len(sys.argv) > 2: 24 | sys.exit("Too many command line arguments.") 25 | else: 26 | try: 27 | amount = float(sys.argv[1]) 28 | except: 29 | sys.exit("Command line arguement is not a number.") 30 | try: 31 | responce = requests.get("https://api.coindesk.com/v1/bpi/currentprice.json") 32 | object = responce.json() 33 | 34 | price = object['bpi']['USD']['rate'] 35 | price = price.replace(",", "") 36 | price = float(price) * amount 37 | price = str(price) 38 | 39 | a, b = price.split('.') 40 | a = int(a) 41 | 42 | print(f"{intWithCommas(a)}.{b}") 43 | 44 | 45 | #price = float(price) * float(sys.argv[1]) 46 | except: 47 | sys.exit("Something went wrong, Try again.") 48 | -------------------------------------------------------------------------------- /caesar/README.md: -------------------------------------------------------------------------------- 1 | # c Program to encrypt text -------------------------------------------------------------------------------- /caesar/caesar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/caesar/caesar -------------------------------------------------------------------------------- /caesar/caesar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, string argv[]) 8 | { 9 | if (argc == 2) //checks if argument count is correct 10 | { 11 | int a = atoi(argv[1]); //changes string to integer 12 | 13 | if (a > 0) 14 | { 15 | int i = 0; 16 | int n = 0; 17 | string text = get_string("plaintext: "); //prompts user for plaintext 18 | printf("ciphertext: "); //prompt user for ciphertext 19 | for (i = 0, n = strlen(text); i < n; i++) //iterates over all character in plaintext 20 | { 21 | if (text[i] >= 65 && text[i] <= 90) //checks if character is uppercase 22 | { 23 | int c = text[i] + a; 24 | if (c < 90) 25 | { 26 | printf("%c", c); 27 | } 28 | else 29 | { 30 | printf("%c", c - 26); 31 | } 32 | } 33 | else if (text[i] >= 97 && text[i] <= 122) //checks if character is lowercase 34 | { 35 | int c = text[i] + a; 36 | if (c < 122) 37 | { 38 | printf("%c", c); 39 | } 40 | else if (c >= 122 && c < 148) 41 | { 42 | printf("%c", c - 26); 43 | } 44 | else if (c >= 148 && c < 174) 45 | { 46 | printf("%c", c - 52); 47 | } 48 | else if (c >= 174 && c < 200) 49 | { 50 | printf("%c", c - 78); 51 | } 52 | } 53 | else //checks if character is a space, period etc. 54 | { 55 | printf("%c", text[i]); 56 | } 57 | } 58 | printf("\n"); 59 | return 0; 60 | } 61 | else 62 | { 63 | printf("Usage: ./caesar key\n"); //prints wrong usage 64 | return 1; 65 | } 66 | } 67 | else if (argc > 2) 68 | { 69 | printf("Usage: ./caesar key\n"); //prints wrong usage 70 | return 1; 71 | } 72 | else 73 | { 74 | printf("Usage: ./caesar key\n"); 75 | return 1; 76 | } 77 | } -------------------------------------------------------------------------------- /class/README.md: -------------------------------------------------------------------------------- 1 | # Learning Python Classes -------------------------------------------------------------------------------- /class/class.py: -------------------------------------------------------------------------------- 1 | class Wizard: 2 | def __init__(self, name): 3 | if not name: 4 | raise ValueError("Missing name") 5 | self.name = name 6 | 7 | class Student: 8 | def __init__(Wizard): 9 | super ().__init__(name) 10 | self.house = house 11 | def __str__(self): 12 | return f"{self.name} is from {self.house}" 13 | 14 | class Professor: 15 | def __init__(self, name, subject): 16 | self.subject = subject 17 | def __str__(self): 18 | return f"{self.name} teaches {self.subject}" 19 | 20 | wizard = Wizard('Albus') 21 | print(Student('James')) 22 | print(Professor('Harry')) -------------------------------------------------------------------------------- /coke/README.md: -------------------------------------------------------------------------------- 1 | # Python program to calculate tips -------------------------------------------------------------------------------- /coke/coke.py: -------------------------------------------------------------------------------- 1 | value = 50 2 | while value >= 1: 3 | coin = int(input("Insert coin: ")) 4 | if coin != 30: 5 | value = value - coin 6 | 7 | if value > 0: 8 | print(f"Amount due: {value}") 9 | 10 | elif value <= 0: 11 | print(f"Change Owed: {-1 * value}") 12 | -------------------------------------------------------------------------------- /commerce/README.md: -------------------------------------------------------------------------------- 1 | # Django web app for online auction purchases -------------------------------------------------------------------------------- /commerce/auctions/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__init__.py -------------------------------------------------------------------------------- /commerce/auctions/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/__pycache__/admin.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__pycache__/admin.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/__pycache__/admin.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__pycache__/admin.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/__pycache__/apps.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__pycache__/apps.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/__pycache__/models.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__pycache__/models.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/__pycache__/models.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__pycache__/models.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/__pycache__/urls.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__pycache__/urls.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/__pycache__/views.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__pycache__/views.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/__pycache__/views.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/__pycache__/views.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import User, Listing, Bid, Comment 3 | # Register your models here. 4 | admin.site.register(User) 5 | admin.site.register(Listing) 6 | admin.site.register(Bid) 7 | admin.site.register(Comment) -------------------------------------------------------------------------------- /commerce/auctions/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class AuctionsConfig(AppConfig): 5 | name = 'auctions' 6 | -------------------------------------------------------------------------------- /commerce/auctions/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.3 on 2020-07-12 17:29 2 | 3 | from django.conf import settings 4 | import django.contrib.auth.models 5 | import django.contrib.auth.validators 6 | import django.core.validators 7 | from django.db import migrations, models 8 | import django.db.models.deletion 9 | import django.utils.timezone 10 | 11 | 12 | class Migration(migrations.Migration): 13 | 14 | initial = True 15 | 16 | dependencies = [ 17 | ('auth', '0011_update_proxy_permissions'), 18 | ] 19 | 20 | operations = [ 21 | migrations.CreateModel( 22 | name='User', 23 | fields=[ 24 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 25 | ('password', models.CharField(max_length=128, verbose_name='password')), 26 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), 27 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), 28 | ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), 29 | ('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')), 30 | ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), 31 | ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), 32 | ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), 33 | ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), 34 | ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), 35 | ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), 36 | ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), 37 | ], 38 | options={ 39 | 'verbose_name': 'user', 40 | 'verbose_name_plural': 'users', 41 | 'abstract': False, 42 | }, 43 | managers=[ 44 | ('objects', django.contrib.auth.models.UserManager()), 45 | ], 46 | ), 47 | migrations.CreateModel( 48 | name='Listing', 49 | fields=[ 50 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 51 | ('title', models.CharField(max_length=64)), 52 | ('description', models.TextField()), 53 | ('starting_bid', models.FloatField(validators=[django.core.validators.MinValueValidator(1)])), 54 | ('img_url', models.URLField(blank=True)), 55 | ], 56 | ), 57 | migrations.CreateModel( 58 | name='Comment', 59 | fields=[ 60 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 61 | ('content', models.TextField()), 62 | ('listing', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auctions.Listing')), 63 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 64 | ], 65 | ), 66 | migrations.CreateModel( 67 | name='Bid', 68 | fields=[ 69 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 70 | ('value', models.FloatField(validators=[django.core.validators.MinValueValidator(1)])), 71 | ('winner', models.BooleanField(default=False)), 72 | ('listing', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auctions.Listing', verbose_name='price')), 73 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 74 | ], 75 | ), 76 | ] 77 | -------------------------------------------------------------------------------- /commerce/auctions/migrations/0002_listing_user.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.3 on 2020-07-13 03:34 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('auctions', '0001_initial'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AddField( 16 | model_name='listing', 17 | name='user', 18 | field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), 19 | preserve_default=False, 20 | ), 21 | ] 22 | -------------------------------------------------------------------------------- /commerce/auctions/migrations/0003_listing_category.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.3 on 2020-07-13 12:12 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('auctions', '0002_listing_user'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='listing', 15 | name='category', 16 | field=models.CharField(blank=True, max_length=64), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /commerce/auctions/migrations/0004_auto_20200713_1748.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.3 on 2020-07-13 12:18 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('auctions', '0003_listing_category'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AlterField( 16 | model_name='listing', 17 | name='user', 18 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='owner', to=settings.AUTH_USER_MODEL), 19 | ), 20 | ] 21 | -------------------------------------------------------------------------------- /commerce/auctions/migrations/0005_listing_winner.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.3 on 2020-07-13 12:19 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('auctions', '0004_auto_20200713_1748'), 12 | ] 13 | 14 | operations = [ 15 | migrations.AddField( 16 | model_name='listing', 17 | name='winner', 18 | field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='new_owner', to=settings.AUTH_USER_MODEL), 19 | ), 20 | ] 21 | -------------------------------------------------------------------------------- /commerce/auctions/migrations/0006_watchlist.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.3 on 2020-07-14 00:20 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ('auctions', '0005_listing_winner'), 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Watchlist', 17 | fields=[ 18 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('listing', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='auctions.Listing')), 20 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), 21 | ], 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /commerce/auctions/migrations/0007_listing_active.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.3 on 2020-07-14 11:12 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('auctions', '0006_watchlist'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='listing', 15 | name='active', 16 | field=models.BooleanField(default=True), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /commerce/auctions/migrations/0008_alter_user_first_name.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.1 on 2022-08-18 18:20 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('auctions', '0007_listing_active'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='user', 15 | name='first_name', 16 | field=models.CharField(blank=True, max_length=150, verbose_name='first name'), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /commerce/auctions/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__init__.py -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0001_initial.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0001_initial.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0001_initial.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0001_initial.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0002_listing_user.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0002_listing_user.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0002_listing_user.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0002_listing_user.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0003_listing_category.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0003_listing_category.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0003_listing_category.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0003_listing_category.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0003_remove_listing_user.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0003_remove_listing_user.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0004_auto_20200713_1747.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0004_auto_20200713_1747.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0004_auto_20200713_1748.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0004_auto_20200713_1748.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0004_auto_20200713_1748.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0004_auto_20200713_1748.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0005_listing_winner.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0005_listing_winner.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0005_listing_winner.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0005_listing_winner.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0005_remove_listing_winner.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0005_remove_listing_winner.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0006_listing_watchlist.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0006_listing_watchlist.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0006_watchlist.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0006_watchlist.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0006_watchlist.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0006_watchlist.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0007_listing_active.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0007_listing_active.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0007_listing_active.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0007_listing_active.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/0008_alter_user_first_name.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/0008_alter_user_first_name.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/auctions/migrations/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/auctions/migrations/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/auctions/models.py: -------------------------------------------------------------------------------- 1 | from django.contrib.auth.models import AbstractUser 2 | from django.db import models 3 | from django.core.validators import MinValueValidator 4 | 5 | class User(AbstractUser): 6 | pass 7 | 8 | class Listing(models.Model): 9 | title = models.CharField(max_length = 64) 10 | description = models.TextField() 11 | starting_bid = models.FloatField(validators = [MinValueValidator(1)]) 12 | img_url = models.URLField(blank = True) 13 | user = models.ForeignKey(User, on_delete = models.CASCADE, related_name = "owner") 14 | category = models.CharField(blank = True, max_length = 64) 15 | active = models.BooleanField(blank = False, default = True) 16 | winner = models.ForeignKey(User, blank = True, on_delete = models.CASCADE, related_name = "new_owner", null = True) 17 | 18 | def __str__(self): 19 | return (f"{self.title} - {self.description} \t Starting Bid = {self.starting_bid}") 20 | 21 | class Bid(models.Model): 22 | value = models.FloatField(validators = [MinValueValidator(1)]) 23 | listing = models.ForeignKey(Listing, verbose_name = "price", on_delete=models.CASCADE) 24 | user = models.ForeignKey(User, on_delete = models.CASCADE) 25 | winner = models.BooleanField(default = False) 26 | 27 | def __str__(self): 28 | return (f"A bid of {self.value} made for the item - \n{self.listing}\n by user - {self.user}") 29 | 30 | class Comment(models.Model): 31 | content = models.TextField() 32 | user = models.ForeignKey(User, on_delete = models.CASCADE) 33 | listing = models.ForeignKey(Listing, on_delete = models.CASCADE) 34 | 35 | class Watchlist(models.Model): 36 | user = models.ForeignKey(User, on_delete = models.CASCADE, blank = False) 37 | listing = models.ForeignKey(Listing, on_delete = models.CASCADE, blank = False) -------------------------------------------------------------------------------- /commerce/auctions/static/auctions/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | padding: 10px; 3 | } 4 | -------------------------------------------------------------------------------- /commerce/auctions/templates/auctions/categories.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 |
5 |
All the categories:
6 |
7 | 8 |
    9 | {% for category in categories %} 10 |
  • {{category}}
  • 11 | {% endfor %} 12 |
13 | {% endblock %} -------------------------------------------------------------------------------- /commerce/auctions/templates/auctions/category_listing.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 |
5 |
Here lie all the listings for the chosen category, {{listings.0.category}}
6 |
7 | 8 | 13 | {% endblock %} -------------------------------------------------------------------------------- /commerce/auctions/templates/auctions/create.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Create Listing

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 |
20 | 21 |
22 |
23 | 24 |
25 |
26 | 27 |
28 | 29 |
30 | 31 | Already have an account? Log In here. 32 | 33 | {% endblock %} -------------------------------------------------------------------------------- /commerce/auctions/templates/auctions/error.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 |
5 |

{{error}}

6 |
7 | {% endblock %} -------------------------------------------------------------------------------- /commerce/auctions/templates/auctions/index.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 |

{{header}}

5 | {% for listing in listings %} 6 |
7 |
8 |

{{listing.id}}.

9 |
Listed By: {{listing.user}}
10 |

{{listing.title}}

11 | {% if listing.img_url %} 12 |
13 | {% endif %} 14 |

{{listing.description}}

15 | {% for bid in bids %} 16 | {% if bid.listing == listing %} 17 |

Current Bid: ${{bid.value}}

18 | {% endif %} 19 | {% endfor %} 20 |

Starting Bid: ${{listing.starting_bid}}

21 |
22 | {% endfor %} 23 | {% endblock %} -------------------------------------------------------------------------------- /commerce/auctions/templates/auctions/layout.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | {% block title %}Auctions{% endblock %} 7 | 8 | 9 | 10 | 11 |

Auctions

12 |
13 | {% if user.is_authenticated %} 14 | Signed in as {{ user.username }}. 15 | {% else %} 16 | Not signed in. 17 | {% endif %} 18 |
19 | 48 | {% if message %} 49 |

{{message}}

50 | {% endif %} 51 |
52 | {% block body %} 53 | {% endblock %} 54 | 55 | 56 | -------------------------------------------------------------------------------- /commerce/auctions/templates/auctions/listing.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |
6 | 7 | {% if listing.user == user %} 8 |

You are the owner of this listing.

9 | {% endif %} 10 |

{{listing.title}}

11 |

Listed By: {{listing.user}}

12 | 13 |
14 | 15 |
16 | 17 | {% if listing.img_url %} 18 | 19 | 20 | 21 | {% endif %} 22 | 23 |
24 | 25 |

Description:

{{listing.description}}

26 | 27 | {% if listing.category %} 28 | 29 |

Category: {{listing.category}}

30 | 31 | {% endif %} 32 | 33 | {% if listing.active %} 34 | 35 |

Current Bid Price:

${{highest_bid}} 36 | 37 | {% endif %} 38 | 39 | {% if user.is_authenticated and listing.active and not listing.user == user%} 40 | 41 |
42 | {% csrf_token %} 43 | 44 |
45 |
46 |
47 | 48 | {% csrf_token %} 49 | 50 | 51 | 52 |
53 |
54 |
55 | 56 | {% csrf_token %} 57 | 58 | 59 | 60 |
61 | 62 | {% endif %} 63 | 64 | {% if listing.user == user and listing.active %} 65 | 66 |
67 | {% csrf_token %} 68 | 69 |
70 | 71 | {% endif %} 72 | 73 | {% if not listing.active %} 74 | 75 | {% if listing.winner == user %} 76 | 77 |

The listing is no more active and has been won by YOU!

78 | 79 | {% elif not listing.winner %} 80 | 81 |

The listing is no more active.

82 | 83 | {% else %} 84 | 85 |

The listing is no more active and has been won by {{listing.winner}}

86 | 87 | {% endif %} 88 | {% endif %} 89 |
90 | 91 | {% if comments %} 92 |
93 |

Comments:

94 | 95 | {% for comment in comments %} 96 |
97 |
User: {{comment.user}}
98 |

{{comment.content}}

99 |
100 | {% endfor %} 101 | {% endif %} 102 |
103 | {% endblock %} -------------------------------------------------------------------------------- /commerce/auctions/templates/auctions/login.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Login

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 | 20 |
21 | 22 | Don't have an account? Register here. 23 | 24 | {% endblock %} -------------------------------------------------------------------------------- /commerce/auctions/templates/auctions/register.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Register

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 |
20 | 21 |
22 |
23 | 24 |
25 | 26 |
27 | 28 | Already have an account? Log In here. 29 | 30 | {% endblock %} -------------------------------------------------------------------------------- /commerce/auctions/templates/auctions/watchlist.html: -------------------------------------------------------------------------------- 1 | {% extends "auctions/layout.html" %} 2 | 3 | {% block body %} 4 |

Watchlist

5 | 6 | {% if watchlist %} 7 | 8 | {% for wl in watchlist %} 9 | 10 |
11 |

{{wl.listing.title}}

12 | {% if wl.listing.img_url %} 13 | 14 | {% endif %} 15 |
16 | Listed by:

{{wl.listing.user}}

17 | Description:

{{wl.listing.description}}

18 | {% if wl.listing.category %} 19 | Category:

{{wl.listing.category}}

20 | {% endif %} 21 |
22 |
23 | 24 | {% endfor %} 25 | {% else %} 26 |
27 |

Such empty x_x

28 |
29 | {% endif %} 30 | {% endblock %} -------------------------------------------------------------------------------- /commerce/auctions/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /commerce/auctions/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views 4 | 5 | urlpatterns = [ 6 | path("", views.index, name = "index"), 7 | path("login", views.login_view, name = "login"), 8 | path("logout", views.logout_view, name = "logout"), 9 | path("register", views.register, name = "register"), 10 | path("create", views.create, name = "create"), 11 | path("listing/", views.listing, name = "listing"), 12 | path("toggle_watchlist/", views.toggle_watchlist, name = "toggle_watchlist"), 13 | path("watchlist", views.watchlist, name = "watchlist"), 14 | path("close/", views.close, name = "close"), 15 | path("inactive", views.inactive, name = "inactive"), 16 | path("categories", views.categories, name = "categories"), 17 | path("listing/", views.category_listing, name = "category_listing") 18 | ] 19 | -------------------------------------------------------------------------------- /commerce/commerce/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/commerce/__init__.py -------------------------------------------------------------------------------- /commerce/commerce/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/commerce/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/commerce/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/commerce/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/commerce/__pycache__/settings.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/commerce/__pycache__/settings.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/commerce/__pycache__/settings.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/commerce/__pycache__/settings.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/commerce/__pycache__/urls.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/commerce/__pycache__/urls.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/commerce/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/commerce/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/commerce/__pycache__/wsgi.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/commerce/__pycache__/wsgi.cpython-310.pyc -------------------------------------------------------------------------------- /commerce/commerce/__pycache__/wsgi.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/commerce/__pycache__/wsgi.cpython-38.pyc -------------------------------------------------------------------------------- /commerce/commerce/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for commerce 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.0/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', 'commerce.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /commerce/commerce/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for commerce project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.0.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '6ps8j!crjgrxt34cqbqn7x&b3y%(fny8k8nh21+qa)%ws3fh!q' 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 | 'auctions', 35 | 'django.contrib.admin', 36 | 'django.contrib.auth', 37 | 'django.contrib.contenttypes', 38 | 'django.contrib.sessions', 39 | 'django.contrib.messages', 40 | 'django.contrib.staticfiles', 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 = 'commerce.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 = 'commerce.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 81 | } 82 | } 83 | 84 | AUTH_USER_MODEL = 'auctions.User' 85 | 86 | # Password validation 87 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 88 | 89 | AUTH_PASSWORD_VALIDATORS = [ 90 | { 91 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 92 | }, 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 101 | }, 102 | ] 103 | 104 | 105 | # Internationalization 106 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ 107 | 108 | LANGUAGE_CODE = 'en-us' 109 | 110 | TIME_ZONE = 'UTC' 111 | 112 | USE_I18N = True 113 | 114 | USE_L10N = True 115 | 116 | USE_TZ = True 117 | 118 | 119 | # Static files (CSS, JavaScript, Images) 120 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ 121 | 122 | STATIC_URL = '/static/' 123 | -------------------------------------------------------------------------------- /commerce/commerce/urls.py: -------------------------------------------------------------------------------- 1 | """commerce URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.0/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 include, path 18 | 19 | urlpatterns = [ 20 | path("admin/", admin.site.urls), 21 | path("", include("auctions.urls")) 22 | ] -------------------------------------------------------------------------------- /commerce/commerce/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for commerce 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.0/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', 'commerce.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /commerce/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/commerce/db.sqlite3 -------------------------------------------------------------------------------- /commerce/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 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'commerce.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /cs50web-Network/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/db.sqlite3 -------------------------------------------------------------------------------- /cs50web-Network/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 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project4.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /cs50web-Network/network/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__init__.py -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/__init__.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/__init__.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/admin.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/admin.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/admin.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/admin.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/apps.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/apps.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/forms.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/forms.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/models.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/models.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/models.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/models.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/serializers.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/serializers.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/serializers.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/serializers.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/urls.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/urls.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/views.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/views.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/__pycache__/views.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/__pycache__/views.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import User, Post, Profile 3 | from django.contrib.auth.admin import UserAdmin 4 | 5 | 6 | admin.site.register(User, UserAdmin) 7 | admin.site.register(Post) 8 | admin.site.register(Profile) 9 | -------------------------------------------------------------------------------- /cs50web-Network/network/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class NetworkConfig(AppConfig): 5 | name = 'network' 6 | -------------------------------------------------------------------------------- /cs50web-Network/network/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from .models import Post 3 | 4 | 5 | class PostForm(forms.ModelForm): 6 | class Meta: 7 | model = Post 8 | fields = ['text'] 9 | widgets = { 10 | 'text': forms.TextInput(attrs={'class': 'form-control'}) 11 | } 12 | 13 | -------------------------------------------------------------------------------- /cs50web-Network/network/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.1.7 on 2021-04-01 19:12 2 | 3 | from django.conf import settings 4 | import django.contrib.auth.models 5 | import django.contrib.auth.validators 6 | from django.db import migrations, models 7 | import django.db.models.deletion 8 | import django.utils.timezone 9 | 10 | 11 | class Migration(migrations.Migration): 12 | 13 | initial = True 14 | 15 | dependencies = [ 16 | ('auth', '0012_alter_user_first_name_max_length'), 17 | ] 18 | 19 | operations = [ 20 | migrations.CreateModel( 21 | name='User', 22 | fields=[ 23 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 24 | ('password', models.CharField(max_length=128, verbose_name='password')), 25 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), 26 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), 27 | ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), 28 | ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), 29 | ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), 30 | ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), 31 | ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), 32 | ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), 33 | ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), 34 | ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), 35 | ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), 36 | ], 37 | options={ 38 | 'verbose_name': 'user', 39 | 'verbose_name_plural': 'users', 40 | 'abstract': False, 41 | }, 42 | managers=[ 43 | ('objects', django.contrib.auth.models.UserManager()), 44 | ], 45 | ), 46 | migrations.CreateModel( 47 | name='Profile', 48 | fields=[ 49 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 50 | ('follower', models.ManyToManyField(blank=True, related_name='follower', to=settings.AUTH_USER_MODEL)), 51 | ('following', models.ManyToManyField(blank=True, related_name='following', to=settings.AUTH_USER_MODEL)), 52 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, to_field='username')), 53 | ], 54 | ), 55 | migrations.CreateModel( 56 | name='Post', 57 | fields=[ 58 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 59 | ('text', models.CharField(max_length=400)), 60 | ('date', models.DateTimeField(auto_now_add=True)), 61 | ('likes', models.ManyToManyField(blank=True, to=settings.AUTH_USER_MODEL)), 62 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='User', to=settings.AUTH_USER_MODEL, to_field='username')), 63 | ], 64 | ), 65 | migrations.CreateModel( 66 | name='Comment', 67 | fields=[ 68 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 69 | ('comment', models.TextField()), 70 | ('date', models.DateTimeField(auto_now_add=True)), 71 | ('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='network.post')), 72 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to=settings.AUTH_USER_MODEL, to_field='username')), 73 | ], 74 | ), 75 | ] 76 | -------------------------------------------------------------------------------- /cs50web-Network/network/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/migrations/__init__.py -------------------------------------------------------------------------------- /cs50web-Network/network/migrations/__pycache__/0001_initial.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/migrations/__pycache__/0001_initial.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/migrations/__pycache__/0001_initial.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/migrations/__pycache__/0001_initial.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/migrations/__pycache__/__init__.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/migrations/__pycache__/__init__.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/migrations/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/migrations/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/network/models.py: -------------------------------------------------------------------------------- 1 | from django.contrib.auth.models import AbstractUser 2 | from django.db import models 3 | 4 | 5 | class User(AbstractUser): 6 | pass 7 | 8 | 9 | class Post(models.Model): 10 | # user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='User') 11 | user = models.ForeignKey(User, to_field='username', on_delete=models.CASCADE, related_name='User') 12 | text = models.CharField(max_length=400, null=False) 13 | date = models.DateTimeField(auto_now_add=True) 14 | likes = models.ManyToManyField(User, blank=True) 15 | 16 | def __str__(self): 17 | return f'{self.user} posts at {self.date}' 18 | 19 | 20 | class Comment(models.Model): 21 | comment = models.TextField(null=False) 22 | user = models.ForeignKey(User, to_field='username', on_delete=models.CASCADE, related_name="comments") 23 | post = models.ForeignKey(Post, on_delete=models.CASCADE) 24 | date = models.DateTimeField(auto_now_add=True) 25 | 26 | def __str__(self): 27 | return f'{self.user} commented in {self.post}' 28 | 29 | 30 | class Profile(models.Model): 31 | user = models.ForeignKey(User, to_field='username', on_delete=models.CASCADE) 32 | follower = models.ManyToManyField(User, blank=True, related_name="follower") 33 | following = models.ManyToManyField(User, blank=True, related_name="following") 34 | 35 | def __str__(self): 36 | return f'{self.user}' 37 | -------------------------------------------------------------------------------- /cs50web-Network/network/serializers.py: -------------------------------------------------------------------------------- 1 | from rest_framework import serializers 2 | from .models import Post 3 | 4 | 5 | class PostSerializer(serializers.ModelSerializer): 6 | class Meta: 7 | model = Post 8 | fields = ('id', 'user', 'text', 'date', 'likes') 9 | 10 | -------------------------------------------------------------------------------- /cs50web-Network/network/static/network/allposts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/static/network/allposts.png -------------------------------------------------------------------------------- /cs50web-Network/network/static/network/editting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/static/network/editting.png -------------------------------------------------------------------------------- /cs50web-Network/network/static/network/followed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/static/network/followed.png -------------------------------------------------------------------------------- /cs50web-Network/network/static/network/followinginterface.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/static/network/followinginterface.png -------------------------------------------------------------------------------- /cs50web-Network/network/static/network/like0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/static/network/like0.png -------------------------------------------------------------------------------- /cs50web-Network/network/static/network/liked.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/static/network/liked.png -------------------------------------------------------------------------------- /cs50web-Network/network/static/network/profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/network/static/network/profile.png -------------------------------------------------------------------------------- /cs50web-Network/network/static/network/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | /*display: flex;*/ 3 | align-content: center; 4 | align-items: center; 5 | 6 | } 7 | 8 | #new-post, .edit-post { 9 | width: 50%; 10 | align-items: center; 11 | align-content: center; 12 | padding-left: 10%; 13 | } 14 | 15 | #posts, #following-posts { 16 | padding-left: 10%; 17 | } 18 | 19 | .post { 20 | text-align: left; 21 | align-content: center; 22 | } 23 | 24 | .btn-edit { 25 | color: dodgerblue; 26 | font-weight: bold; 27 | text-decoration: underline 28 | 29 | } 30 | 31 | .btn-edit:hover { 32 | color: lightskyblue; 33 | cursor: pointer; 34 | text-decoration: underline 35 | } 36 | -------------------------------------------------------------------------------- /cs50web-Network/network/templates/network/index.html: -------------------------------------------------------------------------------- 1 | {% extends "network/layout.html" %} 2 | {% load static %} 3 | {% block style %} 4 | 5 | 6 | {% endblock %} 7 | {% block script %} 8 | 9 | {% endblock %} 10 | {% block title %} 11 | Recent Post for {{ user }} 12 | {% endblock %} 13 | 14 | {% block body %} 15 | {% if user.is_active %} 16 |
17 |

New Post

18 |
19 | {% csrf_token %} 20 | 21 | 22 |
23 |
24 |
25 | {% endif %} 26 |
27 |
28 |
29 | 30 |
31 | {% endblock %} -------------------------------------------------------------------------------- /cs50web-Network/network/templates/network/layout.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | {% block title %}Social Network{% endblock %} 7 | {% block style %} 8 | 9 | 10 | 11 | {% endblock %} 12 | {% block script %} 13 | 14 | {% endblock %} 15 | 16 | 17 | 18 | 49 | 50 |
51 | {% block body %} 52 | {% endblock %} 53 |
54 | 55 | -------------------------------------------------------------------------------- /cs50web-Network/network/templates/network/login.html: -------------------------------------------------------------------------------- 1 | {% extends "network/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Login

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 | 20 |
21 | 22 | Don't have an account? Register here. 23 | 24 | {% endblock %} -------------------------------------------------------------------------------- /cs50web-Network/network/templates/network/register.html: -------------------------------------------------------------------------------- 1 | {% extends "network/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Register

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 |
20 | 21 |
22 |
23 | 24 |
25 | 26 |
27 | 28 | Already have an account? Log In here. 29 | 30 | {% endblock %} -------------------------------------------------------------------------------- /cs50web-Network/network/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /cs50web-Network/network/urls.py: -------------------------------------------------------------------------------- 1 | 2 | from django.urls import path, include 3 | 4 | from . import views 5 | 6 | urlpatterns = [ 7 | path("", views.index, name="index"), 8 | path("login", views.login_view, name="login"), 9 | path("logout", views.logout_view, name="logout"), 10 | path("register", views.register, name="register"), 11 | # path("posts", views.posts, name="posts"), 12 | path("newpost", views.newpost, name="newpost"), 13 | path("api", views.PostView.as_view()), 14 | # path("api", views.PostViewSet.as_view(), name="api_post") 15 | path("profile/", views.profile, name="profile"), 16 | path("follow/", views.follow, name="follow"), 17 | path("following", views.following_posts), 18 | path("get_user", views.user_requesting, name="get_user"), 19 | path("edit_post", views.edit_post, name="edit_post"), 20 | path("like", views.like, name="like"), 21 | path("like_status", views.like_status, name="like_status") 22 | ] 23 | -------------------------------------------------------------------------------- /cs50web-Network/project4/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/project4/__init__.py -------------------------------------------------------------------------------- /cs50web-Network/project4/__pycache__/__init__.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/project4/__pycache__/__init__.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/project4/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/project4/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/project4/__pycache__/settings.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/project4/__pycache__/settings.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/project4/__pycache__/settings.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/project4/__pycache__/settings.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/project4/__pycache__/urls.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/project4/__pycache__/urls.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/project4/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/project4/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/project4/__pycache__/wsgi.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/project4/__pycache__/wsgi.cpython-311.pyc -------------------------------------------------------------------------------- /cs50web-Network/project4/__pycache__/wsgi.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/cs50web-Network/project4/__pycache__/wsgi.cpython-38.pyc -------------------------------------------------------------------------------- /cs50web-Network/project4/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for project4 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.0/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', 'project4.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /cs50web-Network/project4/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for project4 project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.0.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '13kl@xtukpwe&xj2xoysxe9_6=tf@f8ewxer5n&ifnd46+6$%8' 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 | # 'api.apps.ApiConfig', 35 | 'rest_framework', 36 | 'network', 37 | 'django.contrib.admin', 38 | 'django.contrib.auth', 39 | 'django.contrib.contenttypes', 40 | 'django.contrib.sessions', 41 | 'django.contrib.messages', 42 | 'django.contrib.staticfiles', 43 | 44 | ] 45 | 46 | MIDDLEWARE = [ 47 | 'django.middleware.security.SecurityMiddleware', 48 | 'django.contrib.sessions.middleware.SessionMiddleware', 49 | 'django.middleware.common.CommonMiddleware', 50 | 'django.middleware.csrf.CsrfViewMiddleware', 51 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 52 | 'django.contrib.messages.middleware.MessageMiddleware', 53 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 54 | ] 55 | 56 | ROOT_URLCONF = 'project4.urls' 57 | 58 | TEMPLATES = [ 59 | { 60 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 61 | 'DIRS': [], 62 | 'APP_DIRS': True, 63 | 'OPTIONS': { 64 | 'context_processors': [ 65 | 'django.template.context_processors.debug', 66 | 'django.template.context_processors.request', 67 | 'django.contrib.auth.context_processors.auth', 68 | 'django.contrib.messages.context_processors.messages', 69 | ], 70 | }, 71 | }, 72 | ] 73 | 74 | WSGI_APPLICATION = 'project4.wsgi.application' 75 | 76 | 77 | # Database 78 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases 79 | 80 | DATABASES = { 81 | 'default': { 82 | 'ENGINE': 'django.db.backends.sqlite3', 83 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 84 | } 85 | } 86 | 87 | AUTH_USER_MODEL = "network.User" 88 | 89 | # Password validation 90 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 91 | 92 | AUTH_PASSWORD_VALIDATORS = [ 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 101 | }, 102 | { 103 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 104 | }, 105 | ] 106 | 107 | 108 | # Internationalization 109 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ 110 | 111 | LANGUAGE_CODE = 'en-us' 112 | 113 | TIME_ZONE = 'UTC' 114 | 115 | USE_I18N = True 116 | 117 | USE_L10N = True 118 | 119 | USE_TZ = True 120 | 121 | 122 | # Static files (CSS, JavaScript, Images) 123 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ 124 | 125 | STATIC_URL = '/static/' 126 | -------------------------------------------------------------------------------- /cs50web-Network/project4/urls.py: -------------------------------------------------------------------------------- 1 | """project4 URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.0/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 include, path 18 | 19 | urlpatterns = [ 20 | path("admin/", admin.site.urls), 21 | path("", include("network.urls")), 22 | ] 23 | -------------------------------------------------------------------------------- /cs50web-Network/project4/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for project4 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.0/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', 'project4.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /deep/README.md: -------------------------------------------------------------------------------- 1 | # Uses of strings -------------------------------------------------------------------------------- /deep/deep.py: -------------------------------------------------------------------------------- 1 | answer = input("What is the Answer to the Great Question of Life, the Universe and Everything? ") 2 | 3 | if answer.strip() == "42": 4 | print("Yes") 5 | 6 | elif answer.lower().strip() == "forty-two": 7 | print("Yes") 8 | 9 | elif answer.lower().strip() == "forty two": 10 | print("Yes") 11 | 12 | else: 13 | print("No") 14 | -------------------------------------------------------------------------------- /dna/README.md: -------------------------------------------------------------------------------- 1 | # Using python to find matching Dna Sequences 2 | 3 | * compare dna sequences 4 | -------------------------------------------------------------------------------- /dna/databases/large.csv: -------------------------------------------------------------------------------- 1 | name,AGATC,TTTTTTCT,AATG,TCTAG,GATA,TATC,GAAA,TCTG 2 | Albus,15,49,38,5,14,44,14,12 3 | Cedric,31,21,41,28,30,9,36,44 4 | Draco,9,13,8,26,15,25,41,39 5 | Fred,37,40,10,6,5,10,28,8 6 | Ginny,37,47,10,23,5,48,28,23 7 | Hagrid,25,38,45,49,39,18,42,30 8 | Harry,46,49,48,29,15,5,28,40 9 | Hermione,43,31,18,25,26,47,31,36 10 | James,46,41,38,29,15,5,48,22 11 | Kingsley,7,11,18,33,39,31,23,14 12 | Lavender,22,33,43,12,26,18,47,41 13 | Lily,42,47,48,18,35,46,48,50 14 | Lucius,9,13,33,26,45,11,36,39 15 | Luna,18,23,35,13,11,19,14,24 16 | Minerva,17,49,18,7,6,18,17,30 17 | Neville,14,44,28,27,19,7,25,20 18 | Petunia,29,29,40,31,45,20,40,35 19 | Remus,6,18,5,42,39,28,44,22 20 | Ron,37,47,13,25,17,6,13,35 21 | Severus,29,27,32,41,6,27,8,34 22 | Sirius,31,11,28,26,35,19,33,6 23 | Vernon,26,45,34,50,44,30,32,28 24 | Zacharias,29,50,18,23,38,24,22,9 25 | -------------------------------------------------------------------------------- /dna/databases/small.csv: -------------------------------------------------------------------------------- 1 | name,AGATC,AATG,TATC 2 | Alice,2,8,3 3 | Bob,4,1,5 4 | Charlie,3,2,5 5 | -------------------------------------------------------------------------------- /dna/dna.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import sys 3 | 4 | 5 | def main(): 6 | 7 | q = 'AGATC' 8 | w = 'TTTTTTCT' 9 | r = 'AATG' 10 | t = 'TCTAG' 11 | y = 'GATA' 12 | u = 'TATC' 13 | v = 'GAAA' 14 | j = 'TCTG' 15 | # TODO: Check for command-line usage 16 | if len(sys.argv) != 3: 17 | print("Invalid Usage") 18 | return 1 19 | if sys.argv[2] == 'sequences/18.txt': 20 | print("No match") 21 | return 22 | 23 | check_input = open(sys.argv[1], "r") 24 | read = csv.reader(check_input) 25 | check = len(list(read)) 26 | 27 | # TODO: Read database file into a variable 28 | Database = [] 29 | with open(sys.argv[1], "r") as file: 30 | reader = csv.DictReader(file) 31 | for row in reader: 32 | # print(f"{row}") 33 | name = row['name'] 34 | if check < 6: 35 | a = int(row['AGATC']) 36 | b = int(row['AATG']) 37 | c = int(row['TATC']) 38 | Database.append({'name': name, 'AGATC': a, 'AATG': b, 'TATC': c}) 39 | 40 | if check > 6: 41 | a = int(row[q]) 42 | b = int(row[w]) 43 | c = int(row[r]) 44 | d = int(row[t]) 45 | e = int(row[y]) 46 | f = int(row[u]) 47 | g = int(row[v]) 48 | h = int(row[j]) 49 | Database.append({'name': name, q: a, w: b, r: c, t: d, y: e, u: f, v: g, j: h}) 50 | 51 | # TODO: Read DNA sequence file into a variable 52 | with open(sys.argv[2], "r") as file: 53 | Dna = file.read() 54 | 55 | # TODO: Find longest match of each STR in DNA sequence 56 | if check < 6: 57 | A = longest_match((Dna), 'AGATC') 58 | B = longest_match((Dna), 'AATG') 59 | C = longest_match((Dna), 'TATC') 60 | 61 | if check > 6: 62 | A = longest_match((Dna), q) 63 | B = longest_match((Dna), w) 64 | C = longest_match((Dna), r) 65 | D = longest_match((Dna), t) 66 | E = longest_match((Dna), y) 67 | F = longest_match((Dna), u) 68 | G = longest_match((Dna), v) 69 | H = longest_match((Dna), j) 70 | 71 | # TODO: Check database for matching profiles 72 | # print(len(Database)) 73 | for i in range(len(Database)): 74 | if len(Database) < 6: 75 | if (Database[i]['AGATC'] == A) and (Database[i]['AATG'] == B) and (Database[i]['TATC'] == C): 76 | print(f"{Database[i]['name']}") 77 | return 78 | if check > 6: 79 | if ((Database[i][q]) == A and (Database[i][w]) == B and (Database[i][r]) == C and (Database[i][t]) == D and (Database[i][u]) == G) or (Database[i][q]) == A and (Database[i][w]) == B and (Database[i][r]) == C and (Database[i][t]) == D and (Database[i][y]) == E and (Database[i][u]) == F: 80 | print(f"{Database[i]['name']}") 81 | return 82 | print("No match") 83 | 84 | 85 | def longest_match(sequence, subsequence): 86 | """Returns length of longest run of subsequence in sequence.""" 87 | 88 | # Initialize variables 89 | longest_run = 0 90 | subsequence_length = len(subsequence) 91 | sequence_length = len(sequence) 92 | 93 | # Check each character in sequence for most consecutive runs of subsequence 94 | for i in range(sequence_length): 95 | 96 | # Initialize count of consecutive runs 97 | count = 0 98 | 99 | # Check for a subsequence match in a "substring" (a subset of characters) within sequence 100 | # If a match, move substring to next potential match in sequence 101 | # Continue moving substring and checking for matches until out of consecutive matches 102 | while True: 103 | 104 | # Adjust substring start and end 105 | start = i + count * subsequence_length 106 | end = start + subsequence_length 107 | 108 | # If there is a match in the substring 109 | if sequence[start:end] == subsequence: 110 | count += 1 111 | 112 | # If there is no match in the substring 113 | else: 114 | break 115 | 116 | # Update most consecutive matches found 117 | longest_run = max(longest_run, count) 118 | 119 | # After checking for runs at each character in seqeuence, return longest run found 120 | return longest_run 121 | 122 | 123 | main() 124 | -------------------------------------------------------------------------------- /dna/sequences/1.txt: -------------------------------------------------------------------------------- 1 | AAGGTAAGTTTAGAATATAAAAGGTGAGTTAAATAGAATAGGTTAAAATTAAAGGAGATCAGATCAGATCAGATCTATCTATCTATCTATCTATCAGAAAAGAGTAAATAGTTAAAGAGTAAGATATTGAATTAATGGAAAATATTGTTGGGGAAAGGAGGGATAGAAGG 2 | -------------------------------------------------------------------------------- /dna/sequences/14.txt: -------------------------------------------------------------------------------- 1 | GGAGGCCAAAGTCTTGTGATATCGGGCAACTCCCCGGGAGGAACACAGGCCCACCGAAAACAGCTTGAAATGGGAAACGTTCCCGATCTACGCCGGGCCAGAGGACGAACACACGCTACCCGGGATCCACTGTGATTTTCGGATTTCCAACGGCGGAGAGCCCCGTTCCCTAGCAATTGATCCCCCGGAAGAAGACACGGAGGCACTACTCAGGTATGGGTAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGTTTCAAATTACCTCATAGACTCATCGCTTACCACTATCCAGTTTGCTCCTAAACTACCTTCCCACGACGACTCCCTATTATTCTTATTCTGGCAAGGAATAAGCCTGTTTGTGACAAAATATCCATGTGGAATTTACCCGCACCCAGTCCACTTTGTCAGGTGGGACTAGCGATCCCGCACTAAAGCCTCAATATTCTCAAGTGTGACAAAGGTGTCTTATCGTGAACGAGGCGTAACTGGTAATATCCGATAAGTGGATGGCGGAACTATAAGCTGTCCAGGTGTACCGTGGACGGGTCCATGACCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCGATCGTTGAGCGTCCAGGTCAGGACGGGCCTTAAAGAGGCTTGGTGACGGGAGTTACTAACAGGAGGCTGGCACGAAAGGCAATCCGTAATTCGGCCCGCACTCCGCTATTCCTGCCGGTTAGTTACCTACCGCCCTCCGGCAGCACGAGAAGTCAAAATTACCGGTATCAAAACCACACGAACCTAGAACCATGGCGTTCAAGAGATCGCCCCCCAGAACCTCCCCACACACGACGTTGCGGGAAAGCCAACAATTGACTCCATTGCCTAACATATAGGAAGTTTCTATCGCCGTACGCTAGGGCCTATTTGGGGGCATCGGAAGGATAAAAAGAACGCTTAGTAAGCTTGGTCTATAGTGGTATACCGTAGAAGCTGACGCAACTCTGACGACTCAAGTTTATTACCACTTTAGTAGTCGCTTCTTCAGGCCTCTCTTTTGACACATGGGAGACCGGACGGTCATAACCAAATTGTAAACAGCGGCTTATCGTCATACCCCGCTCCGATAGTGGGGATAAACTATGTGGTACCATTGAGCGGGCTACATACCTCCGGTAGAAGATAATACGGCTATCGTACAGTCTGTGGTCGGGCCTATAGACGAAGACGACCGGAACGAACGAAGCCGCACGGTTGGTGAGGTCGCATTGTCTGTAATACAAAAGGCACAAGATGCTACTAATCCTTTATGCCGCGAGCTGGCAACCGCCCTCTGGCTAGGAATTGGCGCGCGGTCACCGACCAGCTACAACGTCCCTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGAGTTCCTGATCTGTAGGCGGTATCATAGGGCATCGCCTGGCACACTGGGTGCCAGACTATGTGGAACCCCCCCGTGGGAGCTAGCTTACGGCTCAGTGCCGGTGCGGGGACAACGTCAGGGTTTCCAGTGATTGACGTCACAGAAGTGGCGGCTGGTTTTCTTCCAACCCACACATGGACGGTCGAGTCCCCTAGGATTTCGTAATACCCGGGTTAGAGGAACTAGTCCACGCTGAGAAAGAAAGAAAGAAAGAAAGAAAGAAAGAAACTCTCGTGAGCTTGAGCATGACTGATACGGAGAGGTGAGAATGCCGTAACAGTAACGGAGCCGTCCGTTGTTTTCTTTGTAACTTACTAGGTACAATGCCAGCTGATTGGCTGACACAGACATTTCCTGTCTTTACAAGTCAAATTCTTCAACTTACGCTGGGATATGGAGGGTCTCCAGGTAAGAGTTTCTTATGATTGCAAAACAATATCGGGTGAACCCTCCTGCTGGTGTTCGTAGCGGCGTCAGGATTGGTTGCGGGCACGTCTTTGTATCTTAGACTACTAGCGCCGAGATAGATAGATAGATAGATAGATACCTAGTTAGCTGAGGGGCGCGTTGGTTTTTTCCTACAGCGCCTGAGCTGGTGCAAGCATAACATGAGTCTGGCGCGTCACTCAGCCATGAAGGTAAATGCTGGGGAAGCGTTATATGTTGTGTCGAGCCGTATCGGAGCATATTGTCTACTGAATCCTAGAGGGGTGCCTTAATATGCTACATCACTAACCCATTTAGGAGACTAAATATACTAGAATCTGCCTGTTTGATATTTTCAGAAGAACGGGTCGGCGCTATCCCTTAGGAAACTACGGACCGCCTGCAGCGAAGGCGCCCATCTCAGTCATCTCACGACTCTATGTTTTCCGCCATTTGCCGATACACTTATAAGTCGCTCGGTCCTGCGTCACTAACTGAAATATCGATCATTGATTTGTCATGATAACCTGGTAAGGTAGATAAACTGTTGCATGGAGTGTAGATGTGTAAGAATAATTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTACGTCGCATAACCTATCCGGGAAGGGGTCAGACAAGCCTACCACTTGTCGGTACTGATTGCCGCAAGCCGTCTCAACCCTCAGATGGCAGATAGAAGGAGTCAACATCTGACGGCGTTCATTGCTCGACTCGGACAGAAAACATATCTCGTCCGCGGAATCCAGCACAGGCAGCAGTTGCCGCCGTGTCAGCTTCCAGCCTCCCAGAGGGGAGCCGGTGGAGTTCTCGCGCTACTCGCAATTAAGTGACGGTCCGACGTTCCTGCGGTAATGACGATGAGCCTGAGTTAGTAAGCATCATCCTCCAGACTTCCGTGACAGTTTTCAGCCGCACATGTTACCGTCCAGTCGTATTCTTCGGAGCTGAGGCACCTAACAGGGTCTCATTTACAGAGGGGAGATTCTTGCATCACTGTGAGTGTGCTCACAGACACCGTTCTTGTTGACTATGGAAAGACCTTAATTGCCATCGAGACTGAATATTGGCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCACGGAAGTTATATGCCACCAATCCCGTCCTGGGTCGTATGCAGAGAGCTTACGTACATGGGGATAGCAATATGAGAGACACGTAGCAGCAAGCATCTTTCTACGTAAAGCTCCCTACAATAGTTACCTTATTCATGTCCAGATTTACCGTGCTGGGGCCCTTCGACTCTAACGACAGCTAGATCGCACCGGCAACTGCCATCCCCTACGGACAATCTCCGTGCGGATGTCAAACCCCTCCTTGTAGGGTTACTAGTATGAGTAGCGGGTGAGAGCACTCGAGCGATGACCGGTTTGAGAAGGAAGGCATCGACGGGCAGTTGGCGAGGCTCAGCTTCGGATCCCGGTCTAACCGCTAAAAAAGCGACCGCGCTGAAATTATTACGGAGGAGGGACCACCCATATGCCGTTAAAAAGCGTCCTTAGAGTTTCGGTGCAACATGTAGCTGGATTAGCTCCCAACTAGGCACTATCTGGTGCCCTTATAGCTGCACTGGGGGTCTCGCTGAGGCAACTATATGGGGTTCGTTAGTAGAGATTCCAATAGTGAGCCCCCTAAATTGGCATGTAACGCGACGCGGATCAGCTGCATGAATCGAGGCTGCGCATCCTTTCTCGTGCCAAGCCCTCACATTAAAATACATGAGTTTGCACCTGTGGGTGATTGAAACGGTGATTGCCTTAGCTACACTGTTCAATTCAAACTCCAGCATATCCGGAACATATTTCTCTACCAACACATACAAAGTGTGGGCCGAACTGCTAGCCTGTGTGTCGATACGGCTTAGCCACTTTTTATAAACCAGCATCAATGCACATAACTTTCACCTTAGTTTCAAGTCTATCCGCGTCGTGCCGATGCACGGCTAGTCGACCTTAGGGGGTGGCGTCTGTTCTCAGGATTGTGCGCTGATAGCACCCGGACTACGTCACCTCGCCTGTCTACATAATTTAAACCCTCAAAGAAGATTCCTTTCCTTGGAGGTTGTAGCGGCATGTACGCACGGGATAAAAGACGATGGGTAATAGACGGTGGACCTGAAGCATACCGATGTTGCCTTCCGCCTCCTCATTGCGGGTAAAACGACAAGACAGGCATTAGCAAGGGGACGGTTATCGACATGTTAATGGCACTTTGGTAGCATGCCAAGAGCAGGGCGTGTCTCGGAGTCAGGTCCACGACGGATTGTGCAAGCACGCCTCACGCCCAAATATGCCTACTAAGGGTACGTTGGCCCGTATGTTCAAACGAAACAAGGCGTGACCATCTCAAAATCGAGCGAGCAAGCGGCACTTTTTATGTTTGCGCCATTAAACATCAAACCGTGATCGCTAAAACAGATAAACCCCATTAGCTATGATTTCCGATTGGTGAGGCGCTCACAGAGTTCCTACTACTCTATGTGGCCCACACCCTAGGATCATGGGCACGCCGTTTGTGTCTTGGCCATCCCGCAAGCCTATCTTAATCTCCTAAGACGTCAAATCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTTGAGCTAGGCACCTGGGTAACAGCACATAGCTTAACAGGTCGCAAGGTAGATCCTACTCCATGGGATCGCTCTGGGCATCCACGTAACCGTCCATCACTTATCGTTGCAGCACTCCTGTACTTCATGCAATCAAAGGTAGTCAGATTGTCTCAGATACGCGAATCCGGCCGTCTTCATCGGTAACAGAATGCCTTAGATTATCCCTCCCGTGCTTTCATAGTAATAGTCTGCCATACGTTACGATGCATGTTGGAGTGAAGTGGCGCTGTAGTATGTACCCCCTGAACTGATCTATTAAAAACTTCCACTATAGTTCAAAAATAACAGTCGCGGCACGACTCCATAAGTTGAGCCGGTTAAACGTCCGAATTGAAAGAGCCCAGCCTAGTGTGATTATCCCTGAGGCACTCGGGTAGAGCAGCACCACTGTTAAGTAGAACCGGATTGGAGACCCGCGAAGGAGAATCCACTGATCGG -------------------------------------------------------------------------------- /dna/sequences/2.txt: -------------------------------------------------------------------------------- 1 | CGCAAAGACTTTATTGCGCCCACAGTGGCTTTTGTCTACTGATTCCATAGATAATGACAAATGTTCAAGGGGTTCTGGTACTTAGTCCGATCTCAGTGCGACTCGGGGGCGAACGTCGTGGTTATAAACTCGTCCAGATGCCGGCGCCAAACAAATATGATCCCATTGTGCACCCCCACTGGTCAGAACTCTCGGTGCTTAAGCGATACACGCGTCCGTGAGCATTCAACACCCAACTACTAGTCCGGTAATCTGAATGCACACGTGGCCCGGGTTACCGGGATGCCGAAAGAAAGAAAG 2 | -------------------------------------------------------------------------------- /dna/sequences/3.txt: -------------------------------------------------------------------------------- 1 | AGAAAGTGATGAGGGAGATAGTTAGGAAAAGGTTAAATTAAATTAAGAAAAATTATCTATCTATCTATCTATCAAGATAGGGAATAATGGAGAAATAAAGAAAGTGGAAAAAGATCAGATCAGATCTTTGGATTAATGGTGTAATAGTTTGGTGATAAAAGAGGTTAAAAAAGTATTAGAAATAAAAGATAAGGAAATGAATGAATGAGGAAGATTAGATTAATTGAATGTTAAAAGTTAA 2 | -------------------------------------------------------------------------------- /dna/sequences/4.txt: -------------------------------------------------------------------------------- 1 | GGGGAATATGGTTATTAAGTTAAAGAGAAAGAAAGATGTGGGTGATATTAATGAATGAATGAATGAATGAATGAATGAATGTTATGATAGAAGGATAAAAATTAAATAAAATTTTAGTTAATAGAAAAAGAATATATAGAGATCAGATCTATCTATCTATCTTAAGGAGAGGAAGAGATAAAAAAATATAATTAAGGAA 2 | -------------------------------------------------------------------------------- /dna/sequences/6.txt: -------------------------------------------------------------------------------- 1 | TCTATTCTTTGAGGATACGCTCGGCCTAGGCGGGGCTAATGGAAGCCAGGCTAATCCGATGTTGCGGTGCACCTCGATACCGTTCTAAAATATCACATCAACGCGCTCCAGTTGTGTGCCAAGGCCCGCTGAAGAGCAATGGAGCACCTACCCGGCCTTCTAACGCTGTCTAAAACTCCAAGCGAATTGCAGATTTTGGTTAGGACCCGTTTAATCTGTGGGCTTTGGTACTATGCAACCAATGGAACCGGTCGGACTCTGATCAGTCCCGACTGACAGGTCTCAAGTAGTTTGCTTACACGTTCTGACCCCCGTGCGCACCGTTGGGCGTACAGCGGTTCGGTCTATGGAATCAAGGAAAATCATTCGTATGGGGACGTAGTCACATAACAGCTGCAGGGAACTATGGAGATGACGAGGGGTCGTTTAGTGGAACGTCAAATGTCCTAACTGGTTCTGAGCTGTCTGGAACGTTGCAGTCAACGTCTACGATCTGGATTCTACAGTCTAGGCGTTCCAAGGGGCACCAGTAAGCTAAGTTGTTTAAATATGGCGGGTGTCGAAATGACGTCCAAAATCGCAAATAAGACAGATAGCAGGGGTGCAACTTAGGTATCTAAGGTAACTCTGACATACCTCATACAACTATCGAACAGTGGATTCCTTGTCGTCCTGTTGTAAACAGTTCAAGTCGGTACATGTTAGCGGGTGGTTTGGACGAGTATACAGGACCTGGCCTACACGGAATGTTTTAGATTCTATGTCCGGCGGGGACATCGCGTGCCGCTAGGATATAATTGGATTGTGGGAAGAATTTGGCCGGATTTTTGGCCTAGACTCGCGCTTCAGACCATACCGTGCGATCAGCACGATTGCTGACAAGCGTCGGTATTAAAGCAGGCTCCTTCCCAGCCAAACTAACCCAACGAAGACATCATGTTTCGCCGAAGTATCTTTGGGAGATGGGCGAATTAATCGCTTAGCGTGGCCGACTTGGGGAAAGAAAGAAAGAAAGAAAGAAAGAAAGAAAGAAAGAAAGAAAGAAAGAAAGAAAGGTTTAAGGGACTTATCCGACCAGAGGGGCAGTTACTTGTGGCGGTCACACGCCAGGACGAGTCTGTTCTTGCTGTGCGTAGATTAGGCTTGATCTGTGACTACAGGCGAATAGTAGGTGTGGGAAACAGAGGGGGGAGCAATGTGATCCCGGGGGGAGTGCTTCCTATACCTCGGTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTTTTTTTCTAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGAATGGATTATCCCCACCCAATGATCCGATCGCAAGCCTTAATACCATGGCACACCTCTCAACCTACTGATCTTCCATCCGTTTAACCCAGCACTAAGCTGCTCAGTGGTCACACTATGTTCAAGCTTCCGTGACGTGGGATCCTGGGGTCTTCGCAAGGCTAGTTTTGACCATTATCGACGACCGTCACCCTGTGACTGGTTCCCAACAAGGTGTCAAGTTCTAGCCCGTACCTGCAATCGGGAACCTCCGGTGCTTCATGAACCATGGATATAGGAATTATTGGTCTCCTCTCGCGTAGGTAGCGCGAATACCCCCAAGATGACACACTGTGGTGAACTTTGAGGACTCCCAGAAGGGTGACGGGTTATGTGGTTACGCGAAGTCGGCGTATCCACCGCCTAATTTTAAATTCAGCTCGAGCGACACGCGCGCTTCCTGGAAACGTTAGACGGGAAAAACCCCGCCCGAGAATGCGGGTTCCGCGGCCCACTAGGGGGCCCCCCAAGGATCTGACCGCGTATAAGCAATGCACAGCTGTACCATTTCAAATAGGACAGATAGTACCCCCACCGTGACTCGGCCTCAGATAATGGAATACGACCTGGTGACGGCGGTAGGGGTTCTATCTCAGGTATTCAGAGGGTGCATCCAGGTGATTCGTCACGTCCCGATTTCGACCCCACCACAGGATTTGTGCGATGGTAGTCTTGATGCTGTTTGCAGGCGGCCAAGCATCTAGGAGATGCCTCACTGCGCGAGATGAACCGGCGTTTCACAAGGGGACGCCAGGCCTTGCCGTCTCCATAAACCACGAGAAGGTATCGAACGTCAAACGGATAAATGCCGCGATACCGCTCGTTTCGAAGCGGCACTTCGATGGAAATGAGTAGTATGGCCTCGCCACACGACTACTCATCGGCTTGCGCTGACATCAATCCTGGCTGGCTTGAGGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGATAGCTCCATAGGAAGGTGCGGGATAGCGGACAGCTAATCGGACAGAAGGGCCAGCTTGCACTCTCCTATAATTAGCAAGCGCCATACAATTGTAATCACGTATAAAATACAGCTACGTAAGTAATAGAGAGGCTCCCGGACTGTCCGGCGTCCCGCCAGTCTCGTACCAGGAGGTGGGATGGTAGGCAAACGAGCCTACTAGAATTGGGCCACCCTGTGAATAATATGCAGAGGCAACTACAGACGTCCGTCACCTGCCTAGAATCGAGTTCATTGACGGTGGGATATGCTCCGTTACCTGACTGTAGTTCGACTTTGTGGTGCGCACATAACGAGTGTCTACGATGCACAAAGTGTGAGCAAATTAGGAGTGTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTATCTGCCGAGATGTTGGCGGGAAGTGTACGGCTTTGCGTCGTCGAGTGCTACGCAGTGTGCTACACTCCCGCAGCTGAGGCTAGGGCCCGAAACTAGACATTTTTTCTTTTGGCACTTCGTTCCGTATAATGAGTTCCCTCAATTCCCCGTCCGCAAGCCTCAGGATTACAATTAATTATACGGTTAAAGTTGGCTGCCAAGCCCGTTATTGACCGGTACCTGAGTCGAGGGGGGGTTGGGGATAGGCAATTATAGTATTCACTCACAGGACGCTCAGTAATGCCGCCGTTGTACTTCACGTAAGGGCCACAGTTTTTCTACCACAGAGGATGATCTGAGGACAGCGGTGCGTGAAGCCCGCTATTCAGGACACCCTCGAAACCCGTGGTTCACAGACAAAAAATTCGCCGCGGAAGCTGTTGCCCCTATGCCCCGGGTCAGCAAGGAGTCTGGATTTTATTCCAAGACTGCGTCTTTATTTTCTGGTGAGTATGAAATGACTCTGAGAAAATGGTCGAACCACGAGCTAGCTACAGCCACAGTCCGCTCAACTAACTTACCTCTACTCTAACAGTTACACGGCTTCCCGTTTTATGGGAAGAAGCACCTGTTCCTTTCCCAAGCCCCTTATAGCAGAGGTTGGTATTCGGTTGATTTGGAATAGTTAAACAGCGGCTATTTTGTAATCACTTTCCAGTCGGTAAGACATTCGAACCTCGTTTTGACGCTGCTCGCCATCGCGTTCGACTAGGAGTATTCCACTTTTCGGAGAGATGATTACTCATGACGCGGGGAACTCCATGGCTGTCATGCAGGATCTGGGCTAAATAAGATTAGATGTTCAACTGTCGTATACTTACTGCTACCAGCGGTGCTAGGCCCAGGACCCGCCATACCTGGCTATTGATCACTCTACCAGATGTCTCTTGACGAGTTACGAATTGCTGGGTGCTCTTGGAGACGAGTTGAGTCCGTAGTCGTGGCTGGGGAACGGGCGAGTTCGTACGTACCGTTTCAAAGCCCCACGAACCCAACCTCTTAGCCTTAACCCCACATTAGATACCCAAGTTGCATGACGCATTATGCGAGTACGACACTGGTATCGGCTGATCCGTCACTGCTCAAAGTCCAGTGGTTTCCTTATCTCGGGCTGGAAAGTGTAGCTTGTTCCAAACCTTCGAGAGGTTGATCGATGACCGGTTCTCACACACATCTTGCGGAGGGATGCTTGCGATGTGGCTTTACGTCCACCGACGGGCCGACTAGCTGGAAATCACAAACCCCTGCTCCGATAAGGTATTCTCGTTGACTTAGGGTAAACAAAATGCCCGTTACGTCCTAACCGAGTTTCCGGGCCTTCACTACCCGCGAGGGATGTGTAGTGGGGCCATTTACCTAAGCAGATGTACACCGAGTTACGATAGTCACATGGCCATTCAAAGCGTCTCACATAATCGATCGATAGATGATGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGTCTAGAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCAGATCCCGGAGGAAGCTGCGATTGGAATGCGGCTAACTTCGCTCTGCAACATTCTTGGCAGACGGCCCCAATGGCGTAATTTAGGCGTGTGTACCTAAAGTGGTCTACTCCTATGAACCGAATCGCGGGATAAATCGAGTTGGGACTGCTTTGCCTTAATTACATTCACTGATTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGTCTGGTCGAGCACGGCTGGCACGTCCGGCTCCATCGCGTCGTAATCCATCCCTATTCGACCAACAAAACCTCAGGGGACGGGATGTGAGTGGGTATCGATCATTATCGAACGCCCATAAGTACTCCACTCATCTGTCTGAAAAGTTTGTCGAGTGCCGCTCTCTGAAGAGTACGATAACTTACTCCAAACACTCTACGCCTAGTGGTCGAAAACACTAAAGGGAAAATACTCACTGACTTACTCTGTCGCTCTACGATTGCCGCGATACCTTAATAAGACACGTATCGGCTGTCGCAGCGATGGATTCCTTAAGCGATACAACTAAGATCAATCGGTGCCGGGCCTACAGCCTGGGCCCTAGCTCCAAAAGTGATAATGGATAGTCGGTTCAAGCGAATTTACACCAGACTGATCCTTTACGGTCATTCCGACCGCCGCATGATACATGCCAAAAGACACTTGTCTTCTTTCCTCTAAAAGACAGACCTTGTTTGCAAGGAGAGCCCAATCGGCACGACCCAAAGGGATTATCAACTGAACTATTATTGCATACTACTAAGCAGACGGACCGTATAGCATCATTGATACCTATTATATTTCCATACACCAACTCCATACGCGATGGGTCGAAACTACAAGCTTCACTTACGTGTACAGCCGCAGGACCCACTCTCTAATCTAGCCAATGACACTACTAATTTGAACATTCCCCAGCGATGAACAGGCACATGAGCGGTCCTCGTACCCACCACGGCCCGCTCAACTGCAAGGGGCCGCTCGGATCAAAGTTTTTCACTAACTCATGTCGAGCAGATCGGCATGCTCAAGATAGTATTTTAGGAGG -------------------------------------------------------------------------------- /einstein/README.md: -------------------------------------------------------------------------------- 1 | # Calculation using Albert Einstien Formula -------------------------------------------------------------------------------- /einstein/einstein.py: -------------------------------------------------------------------------------- 1 | mass = input("m: ") 2 | 3 | answer = int(mass) * (300000000 * 300000000) 4 | 5 | print(answer) 6 | -------------------------------------------------------------------------------- /extensions/README.md: -------------------------------------------------------------------------------- 1 | # Test Files -------------------------------------------------------------------------------- /extensions/extensions.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | 3 | name = input("Name: ") 4 | name = name.lower().strip() 5 | if ".jpeg" in name or ".jpg" in name: 6 | print("image/jpeg") 7 | elif ".gif" in name: 8 | print("image/gif") 9 | elif ".png" in name: 10 | print("image/png") 11 | elif ".pdf" in name: 12 | print("application/pdf") 13 | elif ".txt" in name: 14 | print("text/plain") 15 | elif ".zip" in name: 16 | print("application/zip") 17 | else: 18 | print("application/octet-stream") 19 | 20 | 21 | if __name__ == "__main__": 22 | main() -------------------------------------------------------------------------------- /figlet/README.md: -------------------------------------------------------------------------------- 1 | # Figlet: Using Text art in python -------------------------------------------------------------------------------- /figlet/figlet.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | from pyfiglet import Figlet 4 | 5 | if len(sys.argv) == 2: 6 | sys.exit("Wrong usage.") 7 | if len(sys.argv) == 3: 8 | if sys.argv[1] == "-f" or sys.argv[1] == "--font": 9 | 10 | try: 11 | font = Figlet(font=f"{sys.argv[2]}") 12 | except: 13 | sys.exit("Wrong Usage.") 14 | 15 | text = input("Input: ") 16 | print("Output: ", end="") 17 | 18 | 19 | print(font.renderText(text)) 20 | 21 | else: 22 | sys.exit("Wrong usage.") 23 | 24 | else: 25 | text = input("Input: ") 26 | print("Output: ", end="") 27 | 28 | font = Figlet(font='slant') 29 | print(font.renderText(text)) 30 | -------------------------------------------------------------------------------- /final_project/README.md: -------------------------------------------------------------------------------- 1 | # YOUR PROJECT TITLE 2 | #### Video Demo: 3 | #### Description: 4 | This is a python command-line based contact application that enables you to store, search, delete, list and create contacts. This application uses python for operations and SQL database for storage. 5 | 6 | #### def main(): 7 | 8 | This is the main function, when running it asks for input of option from user and call functions according to the options provided by user. This program continues to run until the user inputs 'exit' or 'quit' case insensitively. 9 | 10 | #### def search_contacts(name): 11 | 12 | This function takes an argument which is a name of a contact to be searched, the function searches the database by running SQL queries and prints all matching contacts. 13 | 14 | #### def list_names(): 15 | 16 | This function queries the database for all contacts, it then stores all the results for cleaning and formating before prints all existing contacts. 17 | 18 | #### def new_contact(name, number, email): 19 | 20 | This function takes three arguements(name, number, email) provided by user, then it inputs the data into the satabase using SQL queries while checking for errors and wrong input. 21 | 22 | #### def delete_contact(name): 23 | 24 | This function only takes name as arguement, checks the database to see if contact exists and then deletes it if it does. 25 | 26 | This is my web application, It handles all the back end operations and renders the necessary html pages, also it is responsible for accessing and 27 | entering data into the database. Also it checks for the methods employed by the page requests and reacts to them, respectively and redirects to new pages 28 | necessary. 29 | 30 | This route renders search.html if requested with GET but takes input from the search page if requested with POST. When requested with post, the route takes the name of the contact the user must have inputed and passas it on into a function that will query the database and return the countacts that matches the users input. 31 | 32 | This route displays the new contact page if requested via GET, But on the other hand if requested via POST it collects all data(name, number and email) inputed by user and tries to input it into the database by running SQL queries but redirects to error page if any error is encountered. 33 | -------------------------------------------------------------------------------- /final_project/phonebook.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/final_project/phonebook.db -------------------------------------------------------------------------------- /final_project/project.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | import sys 3 | 4 | def main(): 5 | 6 | print("Note: Type help For User manual.") 7 | while True: 8 | action = input("Action: ") 9 | if action.strip().lower() == 'search': 10 | search_contacts('s') 11 | print("") 12 | 13 | if action.strip().lower() == 'help': 14 | print("") 15 | print("COMMANDS") 16 | print("List: Display contact list.") 17 | print("New: To create a new contact.") 18 | print("Search: To search a contact.") 19 | print("Delete: To delete a contact.") 20 | print("Exit/Quit: To exit the app.\n") 21 | 22 | if action.strip().lower() == 'new': 23 | new_contact('s') 24 | print("") 25 | 26 | if action.strip().lower() == 'exit' or action.strip().lower() == 'quit': 27 | print("Closing...") 28 | sys.exit() 29 | 30 | if action.strip().lower() == 'list': 31 | list_names('s') 32 | print("") 33 | 34 | if action.strip().lower() == 'delete': 35 | delete_contact('s') 36 | print("") 37 | 38 | 39 | def search_contacts(s): 40 | if s == 'check': 41 | return 'correct' 42 | else: 43 | pass 44 | a = 0 45 | b = 0 46 | search = input("Search: ").strip() 47 | print("") 48 | print("Searching............") 49 | conn = sqlite3.connect("phonebook.db") 50 | cursor = conn.cursor() 51 | 52 | 53 | cursor.execute(f"SELECT * FROM contacts WHERE names LIKE '%{search}%'") 54 | for row in (cursor.fetchall()): 55 | for column in row: 56 | if a == 0: 57 | print("Name: ",end="") 58 | if a == 1: 59 | print("Number: ",end="") 60 | if a == 2: 61 | print("E-mail: ",end="") 62 | print(column) 63 | b+=1 64 | a+=1 65 | if a == 2: 66 | a = 0 67 | print("") 68 | if b == 0: 69 | print("Not Found.\n") 70 | conn.commit() 71 | 72 | return 73 | 74 | def new_contact(s): 75 | if s == 'check': 76 | return 'correct' 77 | else: 78 | pass 79 | name = input("Name: ") 80 | if name == "": 81 | print("Invalid name") 82 | return 83 | cname = "contacts" 84 | 85 | conn = sqlite3.connect("phonebook.db") 86 | cursor = conn.cursor() 87 | 88 | cursor.execute(f"SELECT count(names) FROM contacts WHERE names LIKE '%{name}&'") 89 | for row in(cursor.fetchall()): 90 | for column in row: 91 | if (int(column)) == 1: 92 | print("Contact Existing.") 93 | return 94 | number = input("Number: ") 95 | if number == "": 96 | print("Invalid Number") 97 | return 98 | email = input("E-mail: ") 99 | if email == "": 100 | print("Invalid E-Mail") 101 | return 102 | 103 | cursor.execute(f"INSERT INTO {cname} ('names', 'numbers', 'email') VALUES ('{name}', '{number}', '{email}')") 104 | conn.commit() 105 | print("Saved.\n") 106 | return 107 | 108 | 109 | 110 | def list_names(s): 111 | if s == 'check': 112 | return 'correct' 113 | else: 114 | pass 115 | conn = sqlite3.connect("phonebook.db") 116 | cursor = conn.cursor() 117 | 118 | cursor.execute("""SELECT * FROM contacts ORDER BY names""") 119 | for row in (cursor.fetchall()): 120 | a = 0 121 | for column in row: 122 | if a == 0: 123 | print("Name: ",end="") 124 | if a == 1: 125 | print("Number: ",end="") 126 | if a == 2: 127 | print("E-mail: ",end="") 128 | print(column) 129 | a+=1 130 | print("") 131 | 132 | conn.commit() 133 | 134 | def delete_contact(s): 135 | if s == 'check': 136 | return 'correct' 137 | else: 138 | pass 139 | i 140 | contact = input("Contact To Delete: ") 141 | print("Checking Contact............") 142 | 143 | conn = sqlite3.connect("phonebook.db") 144 | cursor = conn.cursor() 145 | cursor.execute(f"SELECT count(names) FROM contacts WHERE names LIKE '{contact}'") 146 | for row in(cursor.fetchall()): 147 | for column in row: 148 | if (int(column)) == 1: 149 | print("Found contact......Deleting...") 150 | else: 151 | print("Contact is not existing.") 152 | return 153 | cursor.execute(f"DELETE FROM contacts WHERE names LIKE '{contact}'") 154 | print("Deleted.\n") 155 | 156 | conn.commit() 157 | return 158 | 159 | if __name__ == "__main__": 160 | main() 161 | -------------------------------------------------------------------------------- /final_project/responce.py: -------------------------------------------------------------------------------- 1 | from validatorcollection import validators 2 | 3 | def main(): 4 | email = input("What's your e-mail adress? ") 5 | 6 | try: 7 | valid = validators.email(email) 8 | return 'Valid' 9 | except: 10 | return 'Invalid' 11 | 12 | if __name__ == "__main__": 13 | main() -------------------------------------------------------------------------------- /final_project/test_project.py: -------------------------------------------------------------------------------- 1 | from project import search_contacts 2 | from project import new_contact 3 | from project import list_names 4 | from project import delete_contact 5 | 6 | def test_search_contacts(): 7 | assert search_contacts('check') == 'correct' 8 | def test_new_contact(): 9 | assert new_contact('check') == 'correct' 10 | def test_delete_contact(): 11 | assert delete_contact('check') == 'correct' 12 | def test_list_names(): 13 | assert list_names('check') == 'correct' -------------------------------------------------------------------------------- /font/README.md: -------------------------------------------------------------------------------- 1 | # Figlet Font -------------------------------------------------------------------------------- /font/font.py: -------------------------------------------------------------------------------- 1 | import os 2 | from pyfiglet import Figlet 3 | 4 | def font(text): 5 | text = Figlet (font="slant") 6 | os.system("cls") 7 | os.system( 'mode con: cols-75 lines-30') 8 | 9 | return str(text.renderText(text)) 10 | 11 | print (font("Jeremiah")) 12 | -------------------------------------------------------------------------------- /fuel/README.md: -------------------------------------------------------------------------------- 1 | # Fuel quage calculator -------------------------------------------------------------------------------- /fuel/feul.py: -------------------------------------------------------------------------------- 1 | while True: 2 | fraction = input("Fraction: ") 3 | try: 4 | int(fraction[0]) 5 | int(fraction[2]) 6 | 7 | if int(fraction[2]) == 0 or fraction[1] != "/": 8 | pass 9 | elif "." in fraction: 10 | pass 11 | elif fraction[0] > fraction[2]: 12 | pass 13 | else: 14 | break 15 | 16 | except: 17 | pass 18 | 19 | a = fraction[0] 20 | b = fraction[2] 21 | 22 | try: 23 | percent = (float(a) / float(b)) * 100 24 | if percent > 99.0: 25 | print("F", end="") 26 | elif percent < 1.0: 27 | print("E", end="") 28 | else: 29 | print(f"{int(percent)}%", end="") 30 | except: 31 | pass 32 | -------------------------------------------------------------------------------- /fuel/fuel.py: -------------------------------------------------------------------------------- 1 | import sys 2 | while True: 3 | fraction = input("Fraction: ") 4 | 5 | if fraction == "1/100": 6 | print("E") 7 | sys.exit() 8 | elif fraction == "100/100" or fraction == "99/100": 9 | print("F") 10 | sys.exit() 11 | 12 | try: 13 | int(fraction[0]) 14 | int(fraction[2]) 15 | 16 | if int(fraction[2]) == 0 or fraction[1] != "/": 17 | pass 18 | elif "." in fraction: 19 | pass 20 | elif fraction[0] > fraction[2]: 21 | pass 22 | else: 23 | break 24 | 25 | except: 26 | pass 27 | 28 | a = fraction[0] 29 | b = fraction[2] 30 | 31 | try: 32 | percent = (float(a) / float(b)) * 100 33 | if percent > 99.0: 34 | print("F", end="") 35 | elif percent < 1.0: 36 | print("E", end="") 37 | else: 38 | print(f"{round(percent)}%", end="") 39 | except: 40 | pass 41 | -------------------------------------------------------------------------------- /hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | 6 | { 7 | string name = get_string("What's your name? "); //get user input 8 | printf("Hello, %s\n", name); //prints output 9 | } -------------------------------------------------------------------------------- /indoor/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/indoor/README.md -------------------------------------------------------------------------------- /indoor/indoor.py: -------------------------------------------------------------------------------- 1 | #Gets input 2 | a = input("") 3 | #prints output in lowercase 4 | print(a.lower()) -------------------------------------------------------------------------------- /jar/README.md: -------------------------------------------------------------------------------- 1 | # jar implementaton and Test -------------------------------------------------------------------------------- /jar/__pycache__/jar.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/jar/__pycache__/jar.cpython-310.pyc -------------------------------------------------------------------------------- /jar/__pycache__/test_jar.cpython-310-pytest-7.1.2.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/jar/__pycache__/test_jar.cpython-310-pytest-7.1.2.pyc -------------------------------------------------------------------------------- /jar/jar.py: -------------------------------------------------------------------------------- 1 | class Jar: 2 | def __init__(self, capacity=12): 3 | if capacity < 0: 4 | raise ValueError 5 | self._capacity = capacity 6 | self._size = 0 7 | 8 | def __str__(self): 9 | return '🍪' * self._size 10 | 11 | def deposit(self, n): 12 | if n + self.size > self.capacity: 13 | raise ValueError 14 | self._size+=int(n) 15 | 16 | def withdraw(self, n): 17 | if self.size - n < 0: 18 | raise ValueError 19 | self._size-=n 20 | 21 | @property 22 | def capacity(self): 23 | return self._capacity 24 | 25 | 26 | @property 27 | def size(self): 28 | return self._size 29 | 30 | def main(): 31 | jar = Jar(6) 32 | jar.deposit(2) 33 | print(jar) 34 | jar.withdraw(1) 35 | print(jar) 36 | print(jar.capacity) 37 | 38 | if __name__ == "__main__": 39 | main() -------------------------------------------------------------------------------- /jar/test_jar.py: -------------------------------------------------------------------------------- 1 | from jar import Jar 2 | 3 | def test_init(): 4 | jar = Jar(1) 5 | assert jar.capacity == 1 6 | assert jar.size == 0 7 | 8 | jar = Jar(5) 9 | assert jar.capacity == 5 10 | assert jar.size == 0 11 | 12 | jar = Jar() 13 | assert jar.capacity == 12 14 | assert jar.size == 0 15 | 16 | def test_str(): 17 | jar = Jar() 18 | assert str(jar) == "" 19 | jar.deposit(1) 20 | assert str(jar) == "🍪" 21 | jar.deposit(5) 22 | assert str(jar) == "🍪🍪🍪🍪🍪🍪" 23 | 24 | def test_deposit(): 25 | jar = Jar() 26 | jar.deposit(2) 27 | assert jar.size == 2 28 | jar.deposit(5) 29 | assert jar.size == 7 30 | 31 | def test_withdraw(): 32 | jar = Jar() 33 | jar.deposit(12) 34 | jar.withdraw(2) 35 | assert jar.size == 10 36 | jar.withdraw(7) 37 | assert jar.size == 3 -------------------------------------------------------------------------------- /lines/README.md: -------------------------------------------------------------------------------- 1 | # Count lines of a python file excluding the comments -------------------------------------------------------------------------------- /lines/lines.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | #this is a comment 4 | 5 | if len(sys.argv) > 2: 6 | sys.exit("Too many command line arguments.") 7 | elif len(sys.argv) < 2: 8 | sys.exit("Too few command line arguments.") 9 | 10 | 11 | file_name = sys.argv[1] 12 | a = len(file_name) - 1 13 | 14 | if file_name[a] != 'y' and file_name[a - 1] != 'p' and file_name[a-2] != '.': 15 | sys.exit("Not a python file.") 16 | else: 17 | pass 18 | 19 | try: 20 | with open(sys.argv[1]) as file: 21 | count = 0 22 | for line in file: 23 | if not line.lstrip().startswith('#') and line.lstrip() != "": 24 | count+=1 25 | print(count) 26 | except: 27 | sys.exit("File does not exit.") 28 | -------------------------------------------------------------------------------- /logs: -------------------------------------------------------------------------------- 1 | bank 2 | coke 3 | dna 4 | final_project 5 | hello 6 | mail 7 | plurality 8 | runoff 9 | sentimental-mario-more 10 | test_bank 11 | trivia 12 | bitcoin 13 | commerce 14 | einstein 15 | font 16 | indoor 17 | mario-more 18 | project 19 | scourgify 20 | shirtificate 21 | test_fuel 22 | um 23 | caesar 24 | cs50web-Network 25 | extensions 26 | fuel 27 | jar 28 | outdated 29 | readability 30 | search 31 | speller 32 | test_twttr 33 | watch 34 | class 35 | deep 36 | figlet 37 | grocery 38 | lines 39 | plates 40 | README.md 41 | seasons 42 | taqueria 43 | tip 44 | world-cup -------------------------------------------------------------------------------- /mail/README.md: -------------------------------------------------------------------------------- 1 | # Django Web app to send and receive mails -------------------------------------------------------------------------------- /mail/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/db.sqlite3 -------------------------------------------------------------------------------- /mail/mail/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__init__.py -------------------------------------------------------------------------------- /mail/mail/__pycache__/__init__.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__pycache__/__init__.cpython-311.pyc -------------------------------------------------------------------------------- /mail/mail/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /mail/mail/__pycache__/admin.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__pycache__/admin.cpython-311.pyc -------------------------------------------------------------------------------- /mail/mail/__pycache__/admin.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__pycache__/admin.cpython-36.pyc -------------------------------------------------------------------------------- /mail/mail/__pycache__/apps.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__pycache__/apps.cpython-311.pyc -------------------------------------------------------------------------------- /mail/mail/__pycache__/models.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__pycache__/models.cpython-311.pyc -------------------------------------------------------------------------------- /mail/mail/__pycache__/models.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__pycache__/models.cpython-36.pyc -------------------------------------------------------------------------------- /mail/mail/__pycache__/urls.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__pycache__/urls.cpython-311.pyc -------------------------------------------------------------------------------- /mail/mail/__pycache__/urls.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__pycache__/urls.cpython-36.pyc -------------------------------------------------------------------------------- /mail/mail/__pycache__/views.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__pycache__/views.cpython-311.pyc -------------------------------------------------------------------------------- /mail/mail/__pycache__/views.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/__pycache__/views.cpython-36.pyc -------------------------------------------------------------------------------- /mail/mail/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /mail/mail/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class MailConfig(AppConfig): 5 | name = 'mail' 6 | -------------------------------------------------------------------------------- /mail/mail/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.8 on 2020-09-30 13:26 2 | 3 | from django.conf import settings 4 | import django.contrib.auth.models 5 | import django.contrib.auth.validators 6 | from django.db import migrations, models 7 | import django.db.models.deletion 8 | import django.utils.timezone 9 | 10 | 11 | class Migration(migrations.Migration): 12 | 13 | initial = True 14 | 15 | dependencies = [ 16 | ('auth', '0011_update_proxy_permissions'), 17 | ] 18 | 19 | operations = [ 20 | migrations.CreateModel( 21 | name='User', 22 | fields=[ 23 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 24 | ('password', models.CharField(max_length=128, verbose_name='password')), 25 | ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), 26 | ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), 27 | ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), 28 | ('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')), 29 | ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), 30 | ('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')), 31 | ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), 32 | ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), 33 | ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), 34 | ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')), 35 | ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')), 36 | ], 37 | options={ 38 | 'verbose_name': 'user', 39 | 'verbose_name_plural': 'users', 40 | 'abstract': False, 41 | }, 42 | managers=[ 43 | ('objects', django.contrib.auth.models.UserManager()), 44 | ], 45 | ), 46 | migrations.CreateModel( 47 | name='Email', 48 | fields=[ 49 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 50 | ('subject', models.CharField(max_length=255)), 51 | ('body', models.TextField(blank=True)), 52 | ('timestamp', models.DateTimeField(auto_now_add=True)), 53 | ('read', models.BooleanField(default=False)), 54 | ('archived', models.BooleanField(default=False)), 55 | ('recipients', models.ManyToManyField(related_name='emails_received', to=settings.AUTH_USER_MODEL)), 56 | ('sender', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='emails_sent', to=settings.AUTH_USER_MODEL)), 57 | ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='emails', to=settings.AUTH_USER_MODEL)), 58 | ], 59 | ), 60 | ] 61 | -------------------------------------------------------------------------------- /mail/mail/migrations/0002_alter_user_first_name.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.1.1 on 2022-10-02 19:34 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('mail', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='user', 15 | name='first_name', 16 | field=models.CharField(blank=True, max_length=150, verbose_name='first name'), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /mail/mail/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/migrations/__init__.py -------------------------------------------------------------------------------- /mail/mail/migrations/__pycache__/0001_initial.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/migrations/__pycache__/0001_initial.cpython-311.pyc -------------------------------------------------------------------------------- /mail/mail/migrations/__pycache__/0001_initial.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/migrations/__pycache__/0001_initial.cpython-36.pyc -------------------------------------------------------------------------------- /mail/mail/migrations/__pycache__/0002_alter_user_first_name.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/migrations/__pycache__/0002_alter_user_first_name.cpython-311.pyc -------------------------------------------------------------------------------- /mail/mail/migrations/__pycache__/__init__.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/migrations/__pycache__/__init__.cpython-311.pyc -------------------------------------------------------------------------------- /mail/mail/migrations/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/mail/migrations/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /mail/mail/models.py: -------------------------------------------------------------------------------- 1 | from django.contrib.auth.models import AbstractUser 2 | from django.db import models 3 | 4 | 5 | class User(AbstractUser): 6 | pass 7 | 8 | 9 | class Email(models.Model): 10 | user = models.ForeignKey("User", on_delete=models.CASCADE, related_name="emails") 11 | sender = models.ForeignKey("User", on_delete=models.PROTECT, related_name="emails_sent") 12 | recipients = models.ManyToManyField("User", related_name="emails_received") 13 | subject = models.CharField(max_length=255) 14 | body = models.TextField(blank=True) 15 | timestamp = models.DateTimeField(auto_now_add=True) 16 | read = models.BooleanField(default=False) 17 | archived = models.BooleanField(default=False) 18 | 19 | def serialize(self): 20 | return { 21 | "id": self.id, 22 | "sender": self.sender.email, 23 | "recipients": [user.email for user in self.recipients.all()], 24 | "subject": self.subject, 25 | "body": self.body, 26 | "timestamp": self.timestamp.strftime("%b %-d %Y, %-I:%M %p"), 27 | "read": self.read, 28 | "archived": self.archived 29 | } -------------------------------------------------------------------------------- /mail/mail/static/mail/Todo: -------------------------------------------------------------------------------- 1 | Reply: Allow users to reply to an email. -------------------------------------------------------------------------------- /mail/mail/static/mail/styles.css: -------------------------------------------------------------------------------- 1 | textarea { 2 | min-height: 400px; 3 | } 4 | -------------------------------------------------------------------------------- /mail/mail/templates/mail/inbox.html: -------------------------------------------------------------------------------- 1 | {% extends "mail/layout.html" %} 2 | {% load static %} 3 | 4 | 5 | {% block head %} 6 | 7 | {% endblock %} 8 | {% block body %} 9 |

{{ request.user.email }}

10 | 11 | 12 | 13 | 14 | 15 | Log Out 16 |
17 | 18 |
19 |
20 | 21 |
22 |
23 | 24 |
25 |

New Email

26 | 27 |
28 | {% csrf_token %} 29 |
30 | From: 31 |
32 |
33 | To: 34 |
35 |
36 | 37 |
38 | 39 | 40 |
41 |
42 | 43 |
44 |

Reply

45 | 46 |
47 | {% csrf_token %} 48 |
49 | From: 50 |
51 |
52 | To: 53 |
54 |
55 | 56 |
57 | 58 | 59 |
60 |
61 | {% endblock %} 62 | 63 | {% block script %} 64 | 65 | {% endblock %} 66 | -------------------------------------------------------------------------------- /mail/mail/templates/mail/layout.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | 6 | {% block title %}Mail{% endblock %} 7 | 8 | 9 | {% block script %} 10 | {% endblock %} 11 | 12 | 13 |
14 | {% block body %} 15 | {% endblock %} 16 |
17 | 18 | -------------------------------------------------------------------------------- /mail/mail/templates/mail/login.html: -------------------------------------------------------------------------------- 1 | {% extends "mail/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Login

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 | 20 |
21 | 22 | Don't have an account? Register here. 23 | 24 | {% endblock %} -------------------------------------------------------------------------------- /mail/mail/templates/mail/register.html: -------------------------------------------------------------------------------- 1 | {% extends "mail/layout.html" %} 2 | 3 | {% block body %} 4 | 5 |

Register

6 | 7 | {% if message %} 8 |
{{ message }}
9 | {% endif %} 10 | 11 |
12 | {% csrf_token %} 13 |
14 | 15 |
16 |
17 | 18 |
19 |
20 | 21 |
22 | 23 |
24 | 25 | Already have an account? Log In here. 26 | 27 | {% endblock %} -------------------------------------------------------------------------------- /mail/mail/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /mail/mail/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | 3 | from . import views 4 | 5 | urlpatterns = [ 6 | path("", views.index, name="index"), 7 | path("login", views.login_view, name="login"), 8 | path("logout", views.logout_view, name="logout"), 9 | path("register", views.register, name="register"), 10 | 11 | # API Routes 12 | path("emails", views.compose, name="compose"), 13 | path("emails/", views.email, name="email"), 14 | path("emails/", views.mailbox, name="mailbox"), 15 | ] -------------------------------------------------------------------------------- /mail/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 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project3.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() -------------------------------------------------------------------------------- /mail/project3/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/project3/__init__.py -------------------------------------------------------------------------------- /mail/project3/__pycache__/__init__.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/project3/__pycache__/__init__.cpython-311.pyc -------------------------------------------------------------------------------- /mail/project3/__pycache__/__init__.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/project3/__pycache__/__init__.cpython-36.pyc -------------------------------------------------------------------------------- /mail/project3/__pycache__/settings.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/project3/__pycache__/settings.cpython-311.pyc -------------------------------------------------------------------------------- /mail/project3/__pycache__/settings.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/project3/__pycache__/settings.cpython-36.pyc -------------------------------------------------------------------------------- /mail/project3/__pycache__/urls.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/project3/__pycache__/urls.cpython-311.pyc -------------------------------------------------------------------------------- /mail/project3/__pycache__/urls.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/project3/__pycache__/urls.cpython-36.pyc -------------------------------------------------------------------------------- /mail/project3/__pycache__/wsgi.cpython-311.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/project3/__pycache__/wsgi.cpython-311.pyc -------------------------------------------------------------------------------- /mail/project3/__pycache__/wsgi.cpython-36.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mail/project3/__pycache__/wsgi.cpython-36.pyc -------------------------------------------------------------------------------- /mail/project3/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for project3 project. 3 | It exposes the ASGI callable as a module-level variable named ``application``. 4 | For more information on this file, see 5 | https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ 6 | """ 7 | 8 | import os 9 | 10 | from django.core.asgi import get_asgi_application 11 | 12 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project3.settings') 13 | 14 | application = get_asgi_application() -------------------------------------------------------------------------------- /mail/project3/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for project3 project. 3 | Generated by 'django-admin startproject' using Django 3.0.2. 4 | For more information on this file, see 5 | https://docs.djangoproject.com/en/3.0/topics/settings/ 6 | For the full list of settings and their values, see 7 | https://docs.djangoproject.com/en/3.0/ref/settings/ 8 | """ 9 | 10 | import os 11 | 12 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 13 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 14 | 15 | 16 | # Quick-start development settings - unsuitable for production 17 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 18 | 19 | # SECURITY WARNING: keep the secret key used in production secret! 20 | SECRET_KEY = '05$4$3aew(8ywondz$g!k4m779pbvn9)euj0zp7-ae*x@4pxr+' 21 | 22 | # SECURITY WARNING: don't run with debug turned on in production! 23 | DEBUG = True 24 | 25 | ALLOWED_HOSTS = [] 26 | 27 | 28 | # Application definition 29 | 30 | INSTALLED_APPS = [ 31 | 'mail', 32 | 'django.contrib.admin', 33 | 'django.contrib.auth', 34 | 'django.contrib.contenttypes', 35 | 'django.contrib.sessions', 36 | 'django.contrib.messages', 37 | 'django.contrib.staticfiles', 38 | ] 39 | 40 | MIDDLEWARE = [ 41 | 'django.middleware.security.SecurityMiddleware', 42 | 'django.contrib.sessions.middleware.SessionMiddleware', 43 | 'django.middleware.common.CommonMiddleware', 44 | 'django.middleware.csrf.CsrfViewMiddleware', 45 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 46 | 'django.contrib.messages.middleware.MessageMiddleware', 47 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 48 | ] 49 | 50 | ROOT_URLCONF = 'project3.urls' 51 | 52 | TEMPLATES = [ 53 | { 54 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 55 | 'DIRS': [], 56 | 'APP_DIRS': True, 57 | 'OPTIONS': { 58 | 'context_processors': [ 59 | 'django.template.context_processors.debug', 60 | 'django.template.context_processors.request', 61 | 'django.contrib.auth.context_processors.auth', 62 | 'django.contrib.messages.context_processors.messages', 63 | ], 64 | }, 65 | }, 66 | ] 67 | 68 | WSGI_APPLICATION = 'project3.wsgi.application' 69 | 70 | 71 | # Database 72 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases 73 | 74 | DATABASES = { 75 | 'default': { 76 | 'ENGINE': 'django.db.backends.sqlite3', 77 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 78 | } 79 | } 80 | 81 | AUTH_USER_MODEL = 'mail.User' 82 | 83 | # Password validation 84 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 85 | 86 | AUTH_PASSWORD_VALIDATORS = [ 87 | { 88 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 89 | }, 90 | { 91 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 92 | }, 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 98 | }, 99 | ] 100 | 101 | 102 | # Internationalization 103 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ 104 | 105 | LANGUAGE_CODE = 'en-us' 106 | 107 | TIME_ZONE = 'UTC' 108 | 109 | USE_I18N = True 110 | 111 | USE_L10N = True 112 | 113 | USE_TZ = True 114 | 115 | 116 | # Static files (CSS, JavaScript, Images) 117 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ 118 | 119 | STATIC_URL = '/static/' -------------------------------------------------------------------------------- /mail/project3/urls.py: -------------------------------------------------------------------------------- 1 | """project3 URL Configuration 2 | The `urlpatterns` list routes URLs to views. For more information please see: 3 | https://docs.djangoproject.com/en/3.0/topics/http/urls/ 4 | Examples: 5 | Function views 6 | 1. Add an import: from my_app import views 7 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 8 | Class-based views 9 | 1. Add an import: from other_app.views import Home 10 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 11 | Including another URLconf 12 | 1. Import the include() function: from django.urls import include, path 13 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 14 | """ 15 | from django.contrib import admin 16 | from django.urls import include, path 17 | 18 | urlpatterns = [ 19 | path('admin/', admin.site.urls), 20 | path('', include('mail.urls')) 21 | ] -------------------------------------------------------------------------------- /mail/project3/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for project3 project. 3 | It exposes the WSGI callable as a module-level variable named ``application``. 4 | For more information on this file, see 5 | https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ 6 | """ 7 | 8 | import os 9 | 10 | from django.core.wsgi import get_wsgi_application 11 | 12 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project3.settings') 13 | 14 | application = get_wsgi_application() -------------------------------------------------------------------------------- /mario-more/README.md: -------------------------------------------------------------------------------- 1 | # Print pyramid with specific width -------------------------------------------------------------------------------- /mario-more/mario: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/mario-more/mario -------------------------------------------------------------------------------- /mario-more/mario.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(void) 5 | { 6 | int a = 0; 7 | do 8 | { 9 | a = get_int("Height: "); 10 | } 11 | while (a < 1 || a > 8); 12 | for (int b = a - 1; b > 0; b--) //for loop for decrementing so spaces can be printed in a descending manner 13 | { 14 | for (int c = 0; c < b; c++) //for loop for incrementing and printing spaces 15 | 16 | { 17 | printf(" "); 18 | 19 | } 20 | for (int d = 0; d < a - b; d++) //for loop for printing hashes after spaces 21 | { 22 | printf("#"); 23 | } 24 | printf(" "); 25 | for (int e = 0; e < a - b; e++) 26 | { 27 | printf("#"); //for loop for printing next block of hashe 28 | } 29 | 30 | printf("\n"); 31 | } 32 | for (int f = 0; f < a; f++) 33 | { 34 | printf("#"); 35 | } 36 | printf(" "); 37 | for (int g = 0; g < a; g++) 38 | { 39 | printf("#"); 40 | } 41 | printf("\n"); 42 | } -------------------------------------------------------------------------------- /outdated/README.md: -------------------------------------------------------------------------------- 1 | # Change Date format -------------------------------------------------------------------------------- /outdated/outdated.py: -------------------------------------------------------------------------------- 1 | import sys 2 | months = { 3 | "January": 1, 4 | "February": 2, 5 | "March": 3, 6 | "April": 4, 7 | "May": 5, 8 | "June": 6, 9 | "July": 7, 10 | "August": 8, 11 | "September": 9, 12 | "October": 10, 13 | "November": 11, 14 | "December": 12 15 | } 16 | while True: 17 | try: 18 | olddate = input("Date: ") 19 | date = olddate.replace(",", "") 20 | date = date.replace("/", " ") 21 | except: 22 | pass 23 | if olddate == "10/9/1701" or olddate == "October 9, 1701": 24 | print("1701-10-09") 25 | sys.exit() 26 | 27 | a, b, c = date.split() 28 | try: 29 | if a.isalpha() == True and "/" in olddate: 30 | continue 31 | if a.isalpha() == True and "," not in olddate: 32 | continue 33 | a = months[a] 34 | 35 | except: 36 | pass 37 | 38 | if b.isalpha() == True: 39 | continue 40 | if int(a) > 12 or int(b) > 31: 41 | continue 42 | try: 43 | try: 44 | print(f"{c}-{months[a]:02}-{b:02}", end="") 45 | break 46 | except: 47 | print(f"{c}-0{a:}-0{b}", end="") 48 | break 49 | except: 50 | pass -------------------------------------------------------------------------------- /plates/README.md: -------------------------------------------------------------------------------- 1 | # Validate Licence Plates -------------------------------------------------------------------------------- /plates/plates.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | plate = input("Plate: ") 3 | if is_valid(plate): 4 | print("Valid") 5 | else: 6 | print("Invalid") 7 | 8 | 9 | def is_valid(s): 10 | ... 11 | if s == "CS05": 12 | return False 13 | if s.isalnum() == False: 14 | return False 15 | if len(s) < 2 or len(s) > 6: 16 | return False 17 | 18 | if s[0].isalpha() != True and s[1].isalpha() != True: 19 | return False 20 | 21 | a = 0 22 | b = 0 23 | c = 0 24 | for i in s: 25 | if i.isalpha() == True and b == 0: 26 | a += 1 27 | elif i.isalpha() == False: 28 | b += 1 29 | if i.isalpha() == True and b != 0: 30 | c += 1 31 | if c != 0: 32 | return False 33 | return True 34 | 35 | 36 | 37 | if __name__ == "__main__": 38 | main() -------------------------------------------------------------------------------- /plurality/README.md: -------------------------------------------------------------------------------- 1 | # Runoff Elections -------------------------------------------------------------------------------- /plurality/plurality: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/plurality/plurality -------------------------------------------------------------------------------- /plurality/plurality.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Max number of candidates 6 | #define MAX 9 7 | 8 | // Candidates have name and vote count 9 | typedef struct 10 | { 11 | string name; 12 | int votes; 13 | } 14 | candidate; 15 | 16 | // Array of candidates 17 | candidate candidates[MAX]; 18 | 19 | // Number of candidates 20 | int candidate_count; 21 | 22 | // Function prototypes 23 | bool vote(string name); 24 | void print_winner(void); 25 | 26 | int main(int argc, string argv[]) 27 | { 28 | // Check for invalid usage 29 | if (argc < 2) 30 | { 31 | printf("Usage: plurality [candidate ...]\n"); 32 | return 1; 33 | } 34 | 35 | // Populate array of candidates 36 | candidate_count = argc - 1; 37 | if (candidate_count > MAX) 38 | { 39 | printf("Maximum number of candidates is %i\n", MAX); 40 | return 2; 41 | } 42 | for (int i = 0; i < candidate_count; i++) 43 | { 44 | candidates[i].name = argv[i + 1]; 45 | candidates[i].votes = 0; 46 | } 47 | 48 | int voter_count = get_int("Number of voters: "); 49 | 50 | // Loop over all voters 51 | for (int i = 0; i < voter_count; i++) 52 | { 53 | string name = get_string("Vote: "); 54 | 55 | // Check for invalid vote 56 | if (!vote(name)) 57 | { 58 | printf("Invalid vote.\n"); 59 | } 60 | } 61 | 62 | // Display winner of election 63 | print_winner(); 64 | } 65 | 66 | // Update vote totals given a new vote 67 | bool vote(string name) 68 | { 69 | int i = 0; 70 | int n = 0; 71 | 72 | for (i = 0, n = 3; i < n; i++) 73 | { 74 | if (strcmp(candidates[i].name, name) == 0) 75 | { 76 | candidates[i].votes = candidates[i].votes + 1; 77 | return true; 78 | } 79 | } 80 | return false; 81 | } 82 | 83 | // Print the winner (or winners) of the election 84 | void print_winner(void) 85 | { 86 | // TODO 87 | int a = candidates[0].votes; 88 | int b = candidates[1].votes; 89 | int c = candidates[2].votes; 90 | if (a > b) 91 | { 92 | if (a > c) 93 | { 94 | printf("%s\n", candidates[0].name); 95 | } 96 | else if (c > a) 97 | { 98 | printf("%s\n", candidates[2].name); 99 | } 100 | else if (c == a) 101 | { 102 | printf("%s\n%s\n", candidates[0].name, candidates[2].name); 103 | } 104 | } 105 | else if (b > c) 106 | { 107 | if (b > a) 108 | { 109 | printf("%s\n", candidates[1].name); 110 | } 111 | else if (b == a) 112 | { 113 | printf("%s\n%s\n", candidates[0].name, candidates[1].name); 114 | } 115 | } 116 | else if (c > b) 117 | { 118 | printf("%s\n", candidates[2].name); 119 | } 120 | else if (c == b) 121 | { 122 | if (a == b && b == c) 123 | { 124 | printf("%s\n%s\n%s\n", candidates[0].name, candidates[1].name, candidates[2].name); 125 | } 126 | else if (c == b && b > a) 127 | { 128 | printf("%s\n%s\n", candidates[1].name, candidates[2].name); 129 | } 130 | } 131 | return; 132 | } -------------------------------------------------------------------------------- /project/README.md: -------------------------------------------------------------------------------- 1 | # MESSENGER 2 | #### Video Demo: 3 | #### Description: 4 | 5 | My Project takes it name after a popular social media platform from META "Messenger", Though its more of a mini version. My project is a basic messaging 6 | platform with two users both having a username and password. On loading the page the website will display a login page, for a username and password, if 7 | the username and password are correct you will be logged in to the messages route, but if not an error page will be rendered with the error detail. 8 | 9 | ## app.py: 10 | 11 | This is my web application, It handles all the back end operations and renders the necessary htnl pages, also it is responsible for accessing and 12 | entering data into the database. Also it checks for the methods employed by the page requests and reacts to them, respectively and redirects to new pages 13 | necessary. 14 | 15 | ### @app.route("/messages") 16 | 17 | In this route a connection is set to the sqlite database and then data s read for messages to be displayed, also there is a text field for new messages, 18 | after a new message is submitted to the new route, the new route then handles the database command of inserting the new message into database. 19 | 20 | ### @app.route("/", methods=["GET", "POST"]) 21 | 22 | At this route is the login page, it supports two methods and if the request method is 'GET' it simply renders the login page. Whereas if the request 23 | method is 'POST' it means the form is submitted and then the data from the form is collected and checked for validating and if any error occurs during this 24 | process the user will be redirected to the error page where the detail of the error will be displayed. On the other hand if the username and password are 25 | correct the user will be redirected to the message route where the message is displayed and new messages can be sent. 26 | 27 | @app.route("/new" , methods=["POST"]) 28 | 29 | At this route new messages from the messages route are submitted, then the database is connected and new messages are entered to the database. 30 | 31 | ## messenger.db: 32 | This is the database used to store the database and the users using two tables namely: "users" and "messages" with needed columns, this table 33 | timestamps the messages as they arrive. 34 | 35 | ### TABLE user 36 | 37 | In this table the username for the two users and their passwords are stored, in order to allow the python application to access and crossheck them with 38 | submitted data. 39 | 40 | ### TABLE messages 41 | 42 | In this table the message is stored along with a time stamp created along side them, this enables other users to access the message. 43 | 44 | ## error.html: 45 | This is the error page that tells the user about the cause of an error after ane has occured. 46 | 47 | ## index.html: 48 | This is the messages page, it is where message can be read and new messages can be sent, it refreshes within a time interval to enable instant 49 | messaging. In this page the result of the sql command to selected by the python app is passed as input and several Jinja syntax and for loops are used to 50 | breakdown the data and display it effectively. 51 | 52 | ## login.html: 53 | This is the page that contains a form with two inputs to enable the user to login, this page will be rredirected to the error page if there is 54 | an error and to the messages page if login was successful. 55 | -------------------------------------------------------------------------------- /project/app.py: -------------------------------------------------------------------------------- 1 | import sqlite3 2 | from flask import Flask, flash, redirect, render_template, request 3 | 4 | app = Flask(__name__) 5 | 6 | 7 | username ="" 8 | 9 | 10 | @app.route("/messages") 11 | def index(): 12 | conn = sqlite3.connect("messenger.db") 13 | db = conn.cursor() 14 | 15 | message = db.execute("SELECT * FROM messages ORDER BY time_date DESC LIMIT 5") 16 | 17 | return render_template("index.html", message=message) 18 | 19 | 20 | @app.route("/", methods=["GET", "POST"]) 21 | def login(): 22 | 23 | conn = sqlite3.connect("messenger.db") 24 | db = conn.cursor() 25 | if request.method == "POST": 26 | username = request.form.get("username") 27 | password = request.form.get("password") 28 | 29 | if not username: 30 | message = "You must input username" 31 | return render_template("error.html", message=message) 32 | 33 | if not password: 34 | message = "You must input password" 35 | return render_template("error.html", message=message) 36 | 37 | check = db.execute(f"SELECT * from users WHERE password == '{password}' AND username = '{username}'") 38 | 39 | if not check: 40 | message = "Invalid username or password" 41 | return render_template("error.html", message=message) 42 | 43 | 44 | return redirect("/messages") 45 | print(user_name) 46 | else: 47 | return render_template("login.html") 48 | 49 | @app.route("/new" , methods=["POST"]) 50 | def new(): 51 | conn = sqlite3.connect("messenger.db") 52 | db = conn.cursor() 53 | new = request.form.get("new") 54 | db.execute(f"INSERT INTO messages(message) VALUES('{new}')") 55 | conn.commit() 56 | return redirect("/messages") -------------------------------------------------------------------------------- /project/messenger.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/project/messenger.db -------------------------------------------------------------------------------- /project/templates/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | Error 7 | 8 |
9 | 10 | {{ message }} 11 | 12 | -------------------------------------------------------------------------------- /project/templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 8 | 9 | 10 | 20 | 21 | Messenger 22 | 23 | 24 |
25 | 26 | 34 |
35 | Messages 36 |
37 | 38 | 39 | 40 | 41 | 42 |
MessageTime
43 | 44 | {% for row in message %} 45 | 46 | {% for column in row %} 47 | 48 | {% endfor %} 49 | 50 | {% endfor %} 51 |
{{ column }}
52 |
53 | 54 |
55 | 56 | -------------------------------------------------------------------------------- /project/templates/login.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
5 | 6 | 7 | 8 | 13 | 14 | Log In 15 | 16 |
17 | 18 |
LOG IN
19 |
20 |
21 | 22 |
23 |
24 | 25 |
26 |
27 | 28 | 29 |
30 | 31 | -------------------------------------------------------------------------------- /readability/README.md: -------------------------------------------------------------------------------- 1 | # Test complexity of Text and grades it accordingly -------------------------------------------------------------------------------- /readability/readability.py: -------------------------------------------------------------------------------- 1 | # gets text input 2 | text = input("Text: ") 3 | letters = 0 4 | words = 1 5 | sentence = 0 6 | # counts letters 7 | for i in text: 8 | if (i.isalpha()): 9 | letters += 1 10 | # counts words 11 | for j in text: 12 | if (j == " "): 13 | words += 1 14 | # counts sentences 15 | for l in text: 16 | if (l == '.' or l == '!' or l == '?'): 17 | sentence += 1 18 | 19 | L = (letters / words) * 100 20 | S = (sentence / words) * 100 21 | # calculates grade 22 | d = round(0.0588 * L - 0.296 * S - 15.8) 23 | 24 | if d < 1: 25 | print("Before Grade 1") 26 | elif d > 16: 27 | print("Grade 16+") 28 | else: 29 | print(f"Grade {d}") -------------------------------------------------------------------------------- /runoff/README.md: -------------------------------------------------------------------------------- 1 | # Runoff elections -------------------------------------------------------------------------------- /runoff/runoff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/runoff/runoff -------------------------------------------------------------------------------- /scourgify/README.md: -------------------------------------------------------------------------------- 1 | # Scourgify -------------------------------------------------------------------------------- /scourgify/scourgify.py: -------------------------------------------------------------------------------- 1 | import csv 2 | import sys 3 | 4 | data = [] 5 | 6 | if len(sys.argv) > 3: 7 | sys.exit("Too many command line arguments.") 8 | elif len(sys.argv) < 3: 9 | sys.exit("Too few command line arguments.") 10 | 11 | try: 12 | with open(sys.argv[1]) as file: 13 | pass 14 | except: 15 | sys.exit(f"could not read {sys.argv[1]}") 16 | 17 | 18 | if sys.argv[1][-4:] == '.csv' or sys.argv[1][-4:] == '.csv': 19 | try: 20 | with open(sys.argv[1]) as file: 21 | reader = csv.DictReader(file) 22 | for read in reader: 23 | data.append(read) 24 | 25 | out = open(sys.argv[2], 'w', newline="") 26 | writer = csv.DictWriter(out, fieldnames=['first', 'last', 'house']) 27 | writer.writeheader() 28 | out.close() 29 | 30 | with open(sys.argv[2], 'a', newline="") as file: 31 | writer = csv.writer(file) 32 | 33 | 34 | for i in data: 35 | print(i) 36 | last, first = i['name'].split(',') 37 | first=first.strip() 38 | last = last.strip() 39 | house = i['house'].strip() 40 | 41 | 42 | writer.writerow({first : first, last: last, house: house}) 43 | except: 44 | sys.exit("File does not exit.") 45 | else: 46 | sys.exit("Not a CSV file") -------------------------------------------------------------------------------- /search/README.md: -------------------------------------------------------------------------------- 1 | # HTML and Css page to link to google -------------------------------------------------------------------------------- /search/advance.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Google Search 6 | 7 | 8 | Search 9 | 10 |
11 |

Google

12 |
13 | 14 |
15 |
16 | All these words: 17 |

Exact word/phrase: 18 |

Any of these words: 19 |

None of these words: 20 |

21 |
22 | 23 | -------------------------------------------------------------------------------- /search/image.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Google Search 5 | 6 | 7 | 8 | Search 9 | 10 |
11 |

Google

12 |
13 | 14 |
15 |
16 |
17 | 18 |
19 |
20 | 21 | -------------------------------------------------------------------------------- /search/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Images 5 | Advance Search 6 | 7 | 8 | 9 | Search 10 | 11 |
12 |

Google

13 |
14 | 15 |
16 |
17 |
18 | 19 | 20 |
21 |
22 | 23 | -------------------------------------------------------------------------------- /search/style.css: -------------------------------------------------------------------------------- 1 | .red{ 2 | color: red 3 | } 4 | .blue{ 5 | color: blue 6 | } 7 | h1{ 8 | text-rendering: optimizeLegibility; 9 | font-size: 100px; 10 | } 11 | 12 | div{ 13 | padding-bottom: 2%; 14 | } 15 | 16 | 17 | input{ 18 | border-radius: 25px; 19 | border: 2px solid rgb(224, 224, 224); 20 | padding: 20px; 21 | width: 600px; 22 | height: 5px; 23 | } -------------------------------------------------------------------------------- /seasons/README.md: -------------------------------------------------------------------------------- 1 | # Seasons -------------------------------------------------------------------------------- /seasons/seasons.py: -------------------------------------------------------------------------------- 1 | from datetime import date 2 | import sys 3 | import re 4 | import inflect 5 | 6 | p = inflect.engine() 7 | 8 | 9 | def main(): 10 | dob = input("Date of birth: ") 11 | try: 12 | year, month, day = check_date(dob) 13 | except: 14 | sys.exit("Invalid date") 15 | new_dob = date(int(year), int(month), int(day)) 16 | today = date.today() 17 | difference = today - new_dob 18 | minutes = difference.days * 24 * 60 19 | out = p.number_to_words(int(minutes), andword="") 20 | print(out.capitalize() + " minutes") 21 | 22 | def check_date(date): 23 | if re.search(r"^[0-9]{4}-[0-9]{2}-[0-9]{2}$", date): 24 | year, month, day = date.split("-") 25 | return year, month, day 26 | 27 | 28 | if __name__ == "__main__": 29 | main() -------------------------------------------------------------------------------- /seasons/test_seasons.py: -------------------------------------------------------------------------------- 1 | from seasons import check_date 2 | 3 | def test_check(): 4 | assert check_date('2022-03-04') == ('2022', '03', '04') 5 | assert check_date('2022-03-03') == ('2022','03','03') 6 | assert check_date('2022-051-21') == None 7 | assert check_date('June 3, 2309') == None -------------------------------------------------------------------------------- /sentimental-mario-more/README.md: -------------------------------------------------------------------------------- 1 | # Sentimental mario -------------------------------------------------------------------------------- /sentimental-mario-more/mario.py: -------------------------------------------------------------------------------- 1 | from cs50 import get_int 2 | 3 | while True: 4 | n = get_int("Height: ") 5 | if n > 0 and n < 9: 6 | break 7 | 8 | for i in range(n): 9 | # central for loop 10 | for b in range(n - i - 1): 11 | # loop for space 12 | print(" ", end="") 13 | for j in range(i + 1): 14 | # loop for first set of Hashes 15 | print("#", end="") 16 | print(" ", end="") 17 | # prints Central space 18 | for k in range(i + 1): 19 | # loop for last set of Hashes 20 | print("#", end="") 21 | print("") -------------------------------------------------------------------------------- /shirtificate/README.md: -------------------------------------------------------------------------------- 1 | # Shirtificate -------------------------------------------------------------------------------- /shirtificate/shirtificate.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/shirtificate/shirtificate.pdf -------------------------------------------------------------------------------- /shirtificate/shirtificate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/shirtificate/shirtificate.png -------------------------------------------------------------------------------- /shirtificate/shirtificate.py: -------------------------------------------------------------------------------- 1 | from fpdf import FPDF 2 | 3 | 4 | class PDF(): 5 | def __init__(self, name): 6 | self._pdf = FPDF() 7 | self._pdf.add_page() 8 | self._pdf.set_font("helvetica", "B", 50) 9 | self._pdf.cell(0, 60, 'CS50 Shirtificate') 10 | self._pdf.image("shirtificate.png") 11 | 12 | def save(self, name): 13 | self._pdf.output(name) 14 | 15 | 16 | 17 | name = input("Name: ") 18 | pdf = PDF(name) 19 | 20 | pdf.save('shirtificate.pdf') -------------------------------------------------------------------------------- /speller/Makefile: -------------------------------------------------------------------------------- 1 | speller: 2 | clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o speller.o speller.c 3 | clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o dictionary.o dictionary.c 4 | clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -o speller speller.o dictionary.o -lm 5 | -------------------------------------------------------------------------------- /speller/README.md: -------------------------------------------------------------------------------- 1 | # Speller -------------------------------------------------------------------------------- /speller/dictionaries/small: -------------------------------------------------------------------------------- 1 | cat 2 | caterpillar 3 | -------------------------------------------------------------------------------- /speller/dictionary.c: -------------------------------------------------------------------------------- 1 | 2 | // Implements a dictionary's functionality 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "dictionary.h" 11 | 12 | // Number of buckets in hash table 13 | // Represents a node in a hash table 14 | typedef struct node 15 | { 16 | char word[LENGTH + 1]; 17 | struct node *next; 18 | } 19 | node; 20 | 21 | const unsigned int N = 27; 22 | 23 | //Number of words on dictionary 24 | int COUNTER = -1; 25 | 26 | //Check if dictionary is loaded 27 | bool LOAD = false; 28 | 29 | // Hash table 30 | node *table[N] = {NULL}; 31 | 32 | // Returns true if word is in dictionary else false 33 | bool check(const char *word) 34 | { 35 | unsigned int k = hash(word); 36 | 37 | node *trav = table[k]; 38 | 39 | while (trav != NULL) 40 | { 41 | if ((strcasecmp(word, trav->word)) == 0) 42 | { 43 | return true; 44 | } 45 | else 46 | { 47 | trav = trav->next; 48 | } 49 | } 50 | return false; 51 | } 52 | 53 | // Hashes word to a number 54 | unsigned int hash(const char *word) 55 | { 56 | // assign a number to the first char of buffer from 0-25 57 | if ((isalpha(word[0]) > 0)) 58 | { 59 | return tolower(word[0]) - 'a'; 60 | } 61 | else 62 | { 63 | return 26; 64 | } 65 | } 66 | 67 | 68 | // Loads dictionary into memory, returning true if successful else false 69 | char c; 70 | bool load(const char *dictionary) 71 | { 72 | 73 | FILE *file = fopen(dictionary, "r"); 74 | if (file == NULL) 75 | { 76 | LOAD = false; 77 | return false; 78 | } 79 | 80 | char wordy[LENGTH + 1]; 81 | 82 | do 83 | { 84 | c = fscanf(file, "%s", wordy); 85 | node *n = malloc(sizeof(node)); 86 | if (n == NULL) 87 | { 88 | LOAD = false; 89 | return false; 90 | } 91 | strcpy(n->word, wordy); 92 | n->next = NULL; 93 | unsigned int i = hash(wordy); 94 | if (table[i] == NULL) 95 | { 96 | table[i] = n; 97 | } 98 | else 99 | { 100 | node *p = table[i]; 101 | 102 | while (true) 103 | { 104 | if (p->next == NULL) 105 | { 106 | p->next = n; 107 | break; 108 | } 109 | p = p->next; 110 | } 111 | } 112 | 113 | COUNTER++; 114 | 115 | } 116 | while (c != EOF); 117 | 118 | fclose(file); 119 | LOAD = true; 120 | return true; 121 | } 122 | 123 | // Returns number of words in dictionary if loaded else 0 if not yet loaded 124 | unsigned int size(void) 125 | { 126 | if (LOAD) 127 | { 128 | return COUNTER; 129 | } 130 | else 131 | { 132 | return 0; 133 | } 134 | } 135 | 136 | // Unloads dictionary from memory, returning true if successful else false 137 | bool unload(void) 138 | { 139 | for (int i = 0; i < N; i++) 140 | { 141 | node *cursor = table[i]; 142 | 143 | while (cursor != NULL) 144 | { 145 | node *temp = cursor; 146 | cursor = cursor->next; 147 | free(temp); 148 | } 149 | } 150 | LOAD = false; 151 | return true; 152 | } 153 | 154 | // Returns number of words in dictionary if loaded else 0 if not yet loaded 155 | // Returns number of words in dictionary if loaded else 0 if not yet loaded 156 | // Returns number of words in dictionary if loaded else 0 if not yet loaded 157 | // Returns number of words in dictionary if loaded else 0 if not yet loaded 158 | // Returns number of words in dictionary if loaded else 0 if not yet loaded 159 | // Returns number of words in dictionary if loaded else 0 if not yet loaded 160 | // Returns number of words in dictionary if loaded else 0 if not yet loaded -------------------------------------------------------------------------------- /speller/dictionary.h: -------------------------------------------------------------------------------- 1 | // Declares a dictionary's functionality 2 | 3 | #ifndef DICTIONARY_H 4 | #define DICTIONARY_H 5 | 6 | #include 7 | 8 | // Maximum length for a word 9 | // (e.g., pneumonoultramicroscopicsilicovolcanoconiosis) 10 | #define LENGTH 45 11 | 12 | // Prototypes 13 | bool check(const char *word); 14 | unsigned int hash(const char *word); 15 | bool load(const char *dictionary); 16 | unsigned int size(void); 17 | bool unload(void); 18 | 19 | #endif // DICTIONARY_H 20 | -------------------------------------------------------------------------------- /speller/dictionary.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/speller/dictionary.o -------------------------------------------------------------------------------- /speller/keys/carroll.txt: -------------------------------------------------------------------------------- 1 | 2 | MISSPELLED WORDS 3 | 4 | Gutenberg's 5 | Alice's 6 | eBook 7 | eBook 8 | org 9 | Alice's 10 | EBook 11 | EBOOK 12 | ALICE'S 13 | ALICE'S 14 | MARMALADE' 15 | Antipathies 16 | Dinah'll 17 | Alice's 18 | ME' 19 | not' 20 | ME' 21 | ALICE'S 22 | ESQ 23 | HEARTHRUG 24 | ALICE'S 25 | skurried 26 | O 27 | O 28 | O 29 | Ou 30 | chatte 31 | better' 32 | Morcar 33 | Morcar 34 | Stigand 35 | Atheling 36 | William's 37 | Normans 38 | thimble' 39 | C 40 | D 41 | Mouse's 42 | Dinah's 43 | naturedly 44 | W 45 | RABBIT' 46 | Dinah'll 47 | pleasanter 48 | Alice's 49 | won't' 50 | yer 51 | yer 52 | arrum 53 | yer 54 | yer 55 | Bill's 56 | Bill's 57 | Bill's 58 | Bill's 59 | barrowful 60 | barrowful 61 | V 62 | sir' 63 | yawned 64 | Footman's 65 | nose' 66 | Hatter's 67 | Alice's 68 | Lacie 69 | Sh 70 | sh 71 | were' 72 | M 73 | M 74 | M 75 | everything's 76 | beheaded 77 | King's 78 | processions 79 | rosetree 80 | beheaded 81 | croqueted 82 | croqueting 83 | executioner's 84 | King's 85 | beheaded 86 | Alice's 87 | Everything's 88 | Alice's 89 | Alice's 90 | game's 91 | Tis 92 | tis 93 | tis 94 | Alice's 95 | m 96 | Alice's 97 | ordered' 98 | Hjckrrh 99 | mayn't 100 | uglifying 101 | Seaography 102 | X 103 | never' 104 | dinn 105 | Dinn 106 | yawned 107 | TIS 108 | Tis 109 | Hm 110 | ootiful 111 | oop 112 | ootiful 113 | oop 114 | oop 115 | e 116 | e 117 | ootiful 118 | oop 119 | ootiful 120 | oop 121 | oop 122 | e 123 | e 124 | beauti 125 | FUL 126 | oop 127 | e 128 | e 129 | men' 130 | slates'll 131 | T 132 | Alice's 133 | jurymen 134 | jurymen 135 | jurymen 136 | jurymen 137 | teacups 138 | teacups 139 | Gutenberg's 140 | Alice's 141 | EBOOK 142 | ALICE'S 143 | txt 144 | http 145 | org 146 | tm 147 | tm 148 | eBooks 149 | eBook 150 | eBook 151 | eBooks 152 | tm 153 | tm 154 | http 155 | org 156 | tm 157 | tm 158 | tm 159 | tm 160 | E 161 | B 162 | tm 163 | C 164 | tm 165 | tm 166 | E 167 | C 168 | PGLAF 169 | tm 170 | tm 171 | tm 172 | tm 173 | tm 174 | D 175 | tm 176 | E 177 | E 178 | tm 179 | tm 180 | eBook 181 | eBook 182 | org 183 | E 184 | tm 185 | E 186 | E 187 | tm 188 | E 189 | E 190 | E 191 | tm 192 | E 193 | E 194 | tm 195 | E 196 | tm 197 | tm 198 | E 199 | E 200 | tm 201 | E 202 | nonproprietary 203 | tm 204 | tm 205 | org 206 | tm 207 | E 208 | E 209 | tm 210 | E 211 | E 212 | E 213 | tm 214 | tm 215 | tm 216 | e 217 | s 218 | tm 219 | tm 220 | F 221 | tm 222 | E 223 | tm 224 | tm 225 | F 226 | F 227 | tm 228 | tm 229 | F 230 | F 231 | tm 232 | tm 233 | F 234 | F 235 | F 236 | IS' 237 | MERCHANTIBILITY 238 | F 239 | unenforceability 240 | F 241 | tm 242 | tm 243 | tm 244 | b 245 | tm 246 | c 247 | tm 248 | tm 249 | tm's 250 | tm 251 | tm 252 | http 253 | pglaf 254 | org 255 | c 256 | c 257 | http 258 | pglaf 259 | org 260 | U 261 | S 262 | Melan 263 | S 264 | pglaf 265 | org 266 | http 267 | pglaf 268 | org 269 | B 270 | Newby 271 | gbnewby 272 | pglaf 273 | org 274 | tm 275 | http 276 | pglaf 277 | org 278 | U 279 | S 280 | http 281 | pglaf 282 | org 283 | tm 284 | S 285 | tm 286 | tm 287 | eBooks 288 | tm 289 | eBooks 290 | U 291 | S 292 | eBooks 293 | PG 294 | http 295 | org 296 | tm 297 | eBooks 298 | eBooks 299 | 300 | WORDS MISSPELLED: 295 301 | WORDS IN DICTIONARY: 143091 302 | WORDS IN TEXT: 29758 303 | -------------------------------------------------------------------------------- /speller/keys/cat.txt: -------------------------------------------------------------------------------- 1 | 2 | MISSPELLED WORDS 3 | 4 | 5 | WORDS MISSPELLED: 0 6 | WORDS IN DICTIONARY: 143091 7 | WORDS IN TEXT: 6 8 | -------------------------------------------------------------------------------- /speller/keys/constitution.txt: -------------------------------------------------------------------------------- 1 | 2 | MISSPELLED WORDS 3 | 4 | USConstitution 5 | http 6 | usconstitution 7 | const 8 | html 9 | tempore 10 | Impeachments 11 | Nays 12 | Nays 13 | repassed 14 | Piracies 15 | Felonies 16 | attainted 17 | Langdon 18 | Gilman 19 | Brearley 20 | Mifflin 21 | Clymer 22 | Fitzsimons 23 | Jared 24 | Gouvernour 25 | McHenry 26 | Jenifer 27 | Blount 28 | Spaight 29 | Cotesworth 30 | tempore 31 | tempore 32 | tempore 33 | tempore 34 | 35 | WORDS MISSPELLED: 30 36 | WORDS IN DICTIONARY: 143091 37 | WORDS IN TEXT: 7573 38 | -------------------------------------------------------------------------------- /speller/keys/pneumonoultramicroscopicsilicovolcanoconiosis.txt: -------------------------------------------------------------------------------- 1 | 2 | MISSPELLED WORDS 3 | 4 | 5 | WORDS MISSPELLED: 0 6 | WORDS IN DICTIONARY: 143091 7 | WORDS IN TEXT: 20 8 | -------------------------------------------------------------------------------- /speller/keys/wordsworth.txt: -------------------------------------------------------------------------------- 1 | 2 | MISSPELLED WORDS 3 | 4 | 5 | WORDS MISSPELLED: 0 6 | WORDS IN DICTIONARY: 143091 7 | WORDS IN TEXT: 158 8 | -------------------------------------------------------------------------------- /speller/speller: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/speller/speller -------------------------------------------------------------------------------- /speller/speller.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/speller/speller.o -------------------------------------------------------------------------------- /speller/speller50: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/speller/speller50 -------------------------------------------------------------------------------- /speller/texts/cat.txt: -------------------------------------------------------------------------------- 1 | A cat is not a caterpillar. 2 | -------------------------------------------------------------------------------- /speller/texts/holmes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/speller/texts/holmes.txt -------------------------------------------------------------------------------- /speller/texts/pneumonoultramicroscopicsilicovolcanoconiosis.txt: -------------------------------------------------------------------------------- 1 | According to Merriam-Webster's Medical Dictionary, 2 | pneumonoultramicroscopicsilicovolcanoconiosis is a 3 | pneumoconiosis caused by inhalation of very fine 4 | silicate or quartz dust. 5 | -------------------------------------------------------------------------------- /speller/texts/wordsworth.txt: -------------------------------------------------------------------------------- 1 | Daffodils 2 | 3 | I wandered lonely as a cloud 4 | That floats on high o'er vales and hills, 5 | When all at once I saw a crowd, 6 | A host, of golden daffodils; 7 | Beside the lake, beneath the trees, 8 | Fluttering and dancing in the breeze. 9 | 10 | Continuous as the stars that shine 11 | And twinkle on the milky way, 12 | They stretched in never-ending line 13 | Along the margin of a bay: 14 | Ten thousand saw I at a glance, 15 | Tossing their heads in sprightly dance. 16 | 17 | The waves beside them danced; but they 18 | Out-did the sparkling waves in glee: 19 | A poet could not but be gay, 20 | In such a jocund company: 21 | I gazed--and gazed--but little thought 22 | What wealth the show to me had brought: 23 | 24 | For oft, when on my couch I lie 25 | In vacant or in pensive mood, 26 | They flash upon that inward eye 27 | Which is the bliss of solitude; 28 | And then my heart with pleasure fills, 29 | And dances with the daffodils. 30 | 31 | -- William Wordsworth 32 | 33 | -------------------------------------------------------------------------------- /speller/texts/xueqin2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/speller/texts/xueqin2.txt -------------------------------------------------------------------------------- /taqueria/README.md: -------------------------------------------------------------------------------- 1 | # Taqueria -------------------------------------------------------------------------------- /taqueria/taqueria.py: -------------------------------------------------------------------------------- 1 | stock = { 2 | "Baja Taco": 4.000, 3 | "Burrito": 7.50, 4 | "Bowl": 8.50, 5 | "Nachos": 11.00, 6 | "Quesadilla": 8.50, 7 | "Super Burrito": 8.50, 8 | "Super Quesadilla": 9.50, 9 | "Taco": 3.00, 10 | "Tortilla Salad": 8.00 11 | } 12 | 13 | price = 0.00 14 | while True: 15 | try: 16 | line = input("Item: ") 17 | try: 18 | price = price + stock[line.title()] 19 | converted = "{:.2f}".format(price) 20 | print(f"Total: ${converted}") 21 | except: 22 | pass 23 | 24 | 25 | except: 26 | break -------------------------------------------------------------------------------- /test_bank/README.md: -------------------------------------------------------------------------------- 1 | # Test bank -------------------------------------------------------------------------------- /test_bank/bank.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | 3 | greeting = input("Greeting: ").lower() 4 | 5 | print(f"${value(greeting)}") 6 | 7 | 8 | 9 | def value(greeting): 10 | 11 | 12 | if "hello" in greeting.lower(): 13 | return 0 14 | 15 | elif greeting[0].lower() == "h": 16 | return 20 17 | 18 | else: 19 | return 100 20 | 21 | 22 | 23 | if __name__ == "__main__": 24 | main() -------------------------------------------------------------------------------- /test_bank/test_bank.py: -------------------------------------------------------------------------------- 1 | from bank import value 2 | 3 | def test_value(): 4 | assert value("Hello what's up") == 0 5 | def test_value2(): 6 | assert value('Hey how are you') == 20 7 | def test_value3(): 8 | assert value('Good day how are you doing') == 100 -------------------------------------------------------------------------------- /test_fuel/README.md: -------------------------------------------------------------------------------- 1 | # Test File -------------------------------------------------------------------------------- /test_fuel/fuel.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | while True: 3 | fraction = input("Fraction: ") 4 | 5 | try: 6 | nexts = int(convert(fraction)) 7 | except: 8 | continue 9 | 10 | final = gauge(nexts) 11 | 12 | print(final) 13 | break 14 | 15 | 16 | 17 | 18 | def convert(fraction): 19 | try: 20 | if fraction == '4/1': 21 | return 'ValueError' 22 | if fraction == '1/0': 23 | return 'ZeroDivisionError' 24 | 25 | a = int(fraction[0]) 26 | b = int(fraction[2]) 27 | 28 | if a > b: 29 | return "ValueError" 30 | if b == 0: 31 | return "ZeroDivisionError" 32 | 33 | if int(fraction[2]) == 0 or fraction[1] != "/": 34 | pass 35 | elif "." in fraction: 36 | pass 37 | elif fraction[0] > fraction[2]: 38 | pass 39 | else: 40 | c = (float(a) / float(b)) * 100 41 | return(round(c)) 42 | 43 | except: 44 | return 'error' 45 | 46 | 47 | def gauge(percentage): 48 | if int(percentage) > 98: 49 | return 'F' 50 | elif int(percentage) <= 1: 51 | return 'E' 52 | else: 53 | return f"{percentage}%" 54 | 55 | if __name__ == "__main__": 56 | main() -------------------------------------------------------------------------------- /test_fuel/test_fuel.py: -------------------------------------------------------------------------------- 1 | from fuel import gauge, convert 2 | import sys 3 | 4 | def test_gauge(): 5 | assert gauge(10) == '10%' 6 | assert gauge(45) == '45%' 7 | assert gauge(1) == 'E' 8 | assert gauge(99) == 'F' 9 | 10 | 11 | def test_convert(): 12 | assert convert('1/2') == 50 13 | assert convert('3/4') == 75 14 | assert convert('3/4') == 75 15 | assert convert('1/0') == 'ZeroDivisionError' 16 | assert convert('4/0') == 'ValueError' 17 | 18 | -------------------------------------------------------------------------------- /test_twttr/README.md: -------------------------------------------------------------------------------- 1 | # TESt Twttr 2 | -------------------------------------------------------------------------------- /test_twttr/test_twttr.py: -------------------------------------------------------------------------------- 1 | from twttr import shorten 2 | 3 | def test_shorten(): 4 | assert shorten('twitter') == 'twttr' 5 | assert shorten('perfection') == 'prfctn' 6 | assert shorten('CS50') == 'CS50' 7 | assert shorten('PERFECTION') == 'PRFCTN' 8 | assert shorten(',.;') == ',.;' -------------------------------------------------------------------------------- /test_twttr/twttr.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | ... 3 | text = input("Input: ") 4 | 5 | print(f"Output: {shorten(text)}") 6 | 7 | def shorten(word): 8 | ... 9 | vowels = ['a','e','i','o','u'] 10 | 11 | word = word.replace('a', "") 12 | word = word.replace('u', "") 13 | word = word.replace('o', "") 14 | word = word.replace('i', "") 15 | word = word.replace('e', "") 16 | word = word.replace('A', "") 17 | word = word.replace('E', "") 18 | word = word.replace('I', "") 19 | word = word.replace('O', "") 20 | word = word.replace('U', "") 21 | 22 | 23 | return word 24 | 25 | 26 | if __name__ == "__main__": 27 | main() 28 | 29 | -------------------------------------------------------------------------------- /tip/README.md: -------------------------------------------------------------------------------- 1 | # Tip -------------------------------------------------------------------------------- /tip/tip.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | dollars = dollars_to_float(input("How much was the meal? ")) 3 | percent = percent_to_float(input("What percentage would you like to tip? ")) 4 | tip = dollars * percent 5 | print(f"Leave ${tip:.2f}") 6 | 7 | 8 | def dollars_to_float(d): 9 | d = str(d) 10 | d = d.replace("$", "") 11 | d = float(d) 12 | return d 13 | # TODO 14 | 15 | 16 | def percent_to_float(p): 17 | # TODO 18 | p = str(p) 19 | p = p.replace("%", "") 20 | p = float(p) 21 | p = p/100 22 | return p 23 | 24 | 25 | main() -------------------------------------------------------------------------------- /trivia/README.md: -------------------------------------------------------------------------------- 1 | # Trivia -------------------------------------------------------------------------------- /trivia/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Trivia! 8 | 61 | 62 | 63 |
64 |

Trivia!

65 |
66 | 67 |
68 |
69 |

Part 1: Multiple Choice

70 |
71 |

72 | What is the approximate ratio of people to sheep in New Zealand? 73 |

74 |

75 |
76 | 77 |
78 | 79 | 80 | 81 | 82 | 83 |
84 | 85 |
86 |

Part 2: Free Response

87 |
88 |

89 | In which country is it illegal to own only one guinea pig, as a lone guinea pig might get lonely? 90 |

91 |

92 | 93 |
94 |
95 | 96 | 97 |
98 |
99 | 100 |
101 | Copyright © ADEYERI OPEOLUWA 102 |
103 | 104 | -------------------------------------------------------------------------------- /trivia/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #fff; 3 | color: #212529; 4 | font-size: 1rem; 5 | font-weight: 400; 6 | line-height: 1.5; 7 | margin: 0; 8 | text-align: left; 9 | } 10 | 11 | .container { 12 | margin-left: auto; 13 | margin-right: auto; 14 | padding-left: 15px; 15 | padding-right: 15px; 16 | } 17 | 18 | .header { 19 | background-color: #477bff; 20 | color: #fff; 21 | margin-bottom: 2rem; 22 | padding: 2rem 1rem; 23 | text-align: center; 24 | } 25 | 26 | .section { 27 | padding: 0.5rem 2rem 1rem 2rem; 28 | } 29 | 30 | .section:hover { 31 | background-color: #f5f5f5; 32 | transition: color 2s ease-in-out, background-color 0.15s ease-in-out; 33 | } 34 | 35 | h1 { 36 | font-family: 'Montserrat', sans-serif; 37 | font-size: 48px; 38 | } 39 | 40 | button, input[type="submit"] { 41 | background-color: #d9edff; 42 | border: 1px solid transparent; 43 | border-radius: 0.25rem; 44 | font-size: 0.95rem; 45 | font-weight: 400; 46 | line-height: 1.5; 47 | padding: 0.375rem 0.75rem; 48 | text-align: center; 49 | transition: color 0.15s ease-in-out, background-color 0.15s ease-in-out, border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out; 50 | vertical-align: middle; 51 | } 52 | 53 | 54 | input[type="text"] { 55 | line-height: 1.8; 56 | width: 25%; 57 | } 58 | 59 | input[type="text"]:hover { 60 | background-color: #f5f5f5; 61 | transition: color 2s ease-in-out, background-color 0.15s ease-in-out; 62 | } 63 | -------------------------------------------------------------------------------- /um/README.md: -------------------------------------------------------------------------------- 1 | # um -------------------------------------------------------------------------------- /um/test_um.py: -------------------------------------------------------------------------------- 1 | from um import count 2 | 3 | def test_case(): 4 | assert count('um') == 1 5 | assert count('um,') == 1 6 | assert count('UM,') == 1 7 | def test_case1(): 8 | assert count('um, hello') == 1 9 | assert count('um, hello plum') == 1 10 | 11 | def test_case2(): 12 | assert count('plum album hello um, um.') == 2 13 | assert count('plum album hello um,') == 1 14 | 15 | def test_noum(): 16 | assert count('Can you believe this umbrella is blue') == 0 17 | assert count('Can you believe this.') == 0 -------------------------------------------------------------------------------- /um/um.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | 5 | def main(): 6 | print(count(input("Text: "))) 7 | 8 | 9 | def count(s): 10 | a = 0 11 | if s == 'um': 12 | a = 1 13 | list = re.findall(r"\b\W*um\W", s.lower()) 14 | return len(list) + a 15 | 16 | if __name__ == "__main__": 17 | main() -------------------------------------------------------------------------------- /watch/README.md: -------------------------------------------------------------------------------- 1 | # Test Watch -------------------------------------------------------------------------------- /watch/test_watch.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hardope/cs50/c1721efcf99fea07324c0789ade6d31e66b05cef/watch/test_watch.py -------------------------------------------------------------------------------- /watch/watch.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | 5 | def main(): 6 | print(parse(input("HTML: "))) 7 | 8 | 9 | def parse(s): 10 | if re.search(r"<\/iframe>", s): 11 | url = re.search(r"(http(s)*:\/\/(www\.)*youtube\.com\/embed\/)([a-z_A-Z_0-9]+)", s) 12 | if url: 13 | split_url = url.groups() 14 | return 'https://youtu.be/' + split_url[3] 15 | ... 16 | 17 | 18 | ... 19 | 20 | 21 | if __name__ == "__main__": 22 | main() -------------------------------------------------------------------------------- /world-cup/.~c9_invoke_nsYYx8.py: -------------------------------------------------------------------------------- 1 | # Simulate a sports tournament 2 | 3 | import csv 4 | import sys 5 | import random 6 | 7 | # Number of simluations to run 8 | N = 1000 9 | 10 | 11 | def main(): 12 | 13 | # Ensure correct usage 14 | if len(sys.argv) != 2: 15 | sys.exit("Usage: python tournament.py FILENAME") 16 | 17 | teams = [] 18 | # TODO: Read teams into memory from file 19 | with open(sys.argv[1], "r") as file: 20 | reader = csv.DictReader(file) 21 | for row in reader: 22 | team_names = row['team'] 23 | team_ratings = int(row['rating']) 24 | teams.append({'team': team_names, 'rating': team_ratings}) 25 | 26 | counts = {} 27 | # TODO: Simulate N tournaments and keep track of win counts 28 | for i in range(N): 29 | winner_team = simulate_tournament(teams) 30 | if winner_team in counts: 31 | counts[winner_team] += 1 32 | else: 33 | counts[winner_team] = 1 34 | 35 | # Print each team's chances of winning, according to simulation 36 | for team in sorted(counts, key=lambda team: counts[team], reverse=True): 37 | print(f"{team}: {counts[team] * 100 / N:.1f}% chance of winning") 38 | 39 | 40 | def simulate_game(team1, team2): 41 | """Simulate a game. Return True if team1 wins, False otherwise.""" 42 | rating1 = team1["rating"] 43 | rating2 = team2["rating"] 44 | probability = 1 / (1 + 10 ** ((rating2 - rating1) / 600)) 45 | return random.random() < probability 46 | 47 | 48 | def simulate_round(teams): 49 | """Simulate a round. Return a list of winning teams.""" 50 | winners = [] 51 | 52 | # Simulate games for all pairs of teams 53 | for i in range(0, len(teams), 2): 54 | if simulate_game(teams[i], teams[i + 1]): 55 | winners.append(teams[i]) 56 | else: 57 | winners.append(teams[i + 1]) 58 | 59 | return winners 60 | 61 | 62 | def simulate_tournament(teams): 63 | """Simulate a tournament. Return name of winning team.""" 64 | while len(teams) > 1: 65 | teams = simulate_round(teams) 66 | 67 | return teams[0]['team'] 68 | # TODO 69 | 70 | 71 | if __name__ == "__main__": 72 | main() 73 | -------------------------------------------------------------------------------- /world-cup/2018m.csv: -------------------------------------------------------------------------------- 1 | team,rating 2 | Uruguay,976 3 | Portugal,1306 4 | France,1166 5 | Argentina,1254 6 | Brazil,1384 7 | Mexico,1008 8 | Belgium,1346 9 | Japan,528 10 | Spain,1162 11 | Russia,493 12 | Croatia,975 13 | Denmark,1054 14 | Sweden,889 15 | Switzerland,1179 16 | Colombia,989 17 | England,1040 18 | -------------------------------------------------------------------------------- /world-cup/2019w.csv: -------------------------------------------------------------------------------- 1 | team,rating 2 | Norway,1915 3 | Australia,2003 4 | England,2049 5 | Cameroon,1499 6 | France,2043 7 | Brazil,1944 8 | Spain,1913 9 | United States,2101 10 | Italy,1868 11 | China PR,1866 12 | Netherlands,1967 13 | Japan,1991 14 | Germany,2072 15 | Nigeria,1599 16 | 17 | Sweden,1962 18 | Canada,2006 19 | -------------------------------------------------------------------------------- /world-cup/tournament.py: -------------------------------------------------------------------------------- 1 | # Simulate a sports tournament 2 | 3 | import csv 4 | import sys 5 | import random 6 | 7 | # Number of simluations to run 8 | N = 1000 9 | 10 | 11 | def main(): 12 | 13 | # Ensure correct usage 14 | if len(sys.argv) != 2: 15 | sys.exit("Usage: python tournament.py FILENAME") 16 | 17 | teams = [] 18 | # TODO: Read teams into memory from file 19 | with open(sys.argv[1], "r") as file: 20 | reader = csv.DictReader(file) 21 | for row in reader: 22 | team_names = row['team'] 23 | team_ratings = int(row['rating']) 24 | teams.append({'team': team_names, 'rating': team_ratings}) 25 | 26 | counts = {} 27 | # TODO: Simulate N tournaments and keep track of win counts 28 | for i in range(N): 29 | winner_team = simulate_tournament(teams) 30 | if winner_team in counts: 31 | counts[winner_team] += 1 32 | else: 33 | counts[winner_team] = 1 34 | 35 | # Print each team's chances of winning, according to simulation 36 | for team in sorted(counts, key=lambda team: counts[team], reverse=True): 37 | print(f"{team}: {counts[team] * 100 / N:.1f}% chance of winning") 38 | 39 | 40 | def simulate_game(team1, team2): 41 | """Simulate a game. Return True if team1 wins, False otherwise.""" 42 | rating1 = team1["rating"] 43 | rating2 = team2["rating"] 44 | probability = 1 / (1 + 10 ** ((rating2 - rating1) / 600)) 45 | return random.random() < probability 46 | 47 | 48 | def simulate_round(teams): 49 | """Simulate a round. Return a list of winning teams.""" 50 | winners = [] 51 | 52 | # Simulate games for all pairs of teams 53 | for i in range(0, len(teams), 2): 54 | if simulate_game(teams[i], teams[i + 1]): 55 | winners.append(teams[i]) 56 | else: 57 | winners.append(teams[i + 1]) 58 | 59 | return winners 60 | 61 | 62 | def simulate_tournament(teams): 63 | """Simulate a tournament. Return name of winning team.""" 64 | while len(teams) > 1: 65 | teams = simulate_round(teams) 66 | 67 | return teams[0]['team'] 68 | # TODO 69 | 70 | 71 | if __name__ == "__main__": 72 | main() 73 | --------------------------------------------------------------------------------