Initial commit

This commit is contained in:
Shav Kinderlehrer 2024-06-19 16:08:03 -04:00
commit a81ce5bcbe
4 changed files with 181 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.env.sh
venv/

61
flake.lock Normal file
View File

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1718318537,
"narHash": "sha256-4Zu0RYRcAY/VWuu6awwq4opuiD//ahpc2aFHg2CWqFY=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "e9ee548d90ff586a6471b4ae80ae9cfcbceb3420",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

28
flake.nix Normal file
View File

@ -0,0 +1,28 @@
{
description = "A very basic python flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
shell = "zsh";
in {
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
python3
pyright
black
];
OPENAI_API_BASE="https://ai.trkt.in";
shellHook = ''
source .env.sh
exec ${shell}
'';
};
});
}

90
src/main.py Normal file
View File

@ -0,0 +1,90 @@
import os
from pyowm.owm import OWM
from openai import OpenAI
from datetime import datetime
number_map = {
"0": "zero",
"1": "one",
"2": "two",
"3": "three",
"4": "four",
"5": "six",
"6": "six",
"7": "seven",
"8": "eight",
"9": "nine",
"10": "ten",
"11": "eleven",
"12": "twelve",
"13": "thirteen",
"14": "fourteen",
"15": "fifteen",
"16": "sixteen",
"17": "seventeen",
"18": "eighteen",
"19": "nineteen",
"20": "twenty",
"30": "thirty",
"40": "forty",
"50": "fifty",
}
def serialize_time_part(part):
part_string = ""
if part in number_map:
part_string += number_map[part]
else:
tens_str = number_map[f"{part[0]}0"]
ones_str = number_map[part[1]]
part_string += f"{tens_str}-{ones_str}"
return part_string
def serialize_time(time):
hour = str(time.hour)
if time.hour > 12:
hour = str(time.hour - 12)
hour = serialize_time_part(hour)
minute = str(time.minute)
if time.minute < 10:
minute = f"o'{serialize_time_part(minute)}"
else:
minute = serialize_time_part(minute)
time_string = f"{hour} {minute}"
return time_string
def generate_rhyme(time):
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[
{
"role": "user",
"content": f"Finish this sentence about the time with a rhyme. It's {time}, ",
}
],
)
rhyme = response.choices[0].message.content
return f"It's {time} {rhyme}"
def get_weather():
pass
def main():
use_time = datetime.now()
serialized_time = serialize_time(use_time)
print(serialized_time)
sentence = generate_rhyme(serialized_time)
weather = get_weather()
print(sentence)
print(weather)
if __name__ == "__main__":
main()