Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/appInsightsSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,258 changes: 1,258 additions & 0 deletions .idea/caches/deviceStreaming.xml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions .idea/codespaces-flask.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 0 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
# GitHub Codespaces ♥️ Flask

Welcome to your shiny new Codespace running Flask! We've got everything fired up and running for you to explore Flask.

You've got a blank canvas to work on from a git perspective as well. There's a single initial commit with the what you're seeing right now - where you go from here is up to you!

Everything you do here is contained within this one codespace. There is no repository on GitHub yet. If and when you’re ready you can click "Publish Branch" and we’ll create your repository and push up your project. If you were just exploring then and have no further need for this code then you can simply delete your codespace and it's gone forever.

To run this application:

```
flask --debug run
```
12 changes: 12 additions & 0 deletions app2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from flask import Flask, jsonify
import random

app = Flask(__name__)

@app.route('/random', methods=['GET'])
def random_number():
number = random.randint(1, 100)
return jsonify({'random_number': number})

if __name__ == '__main__':
app.run(debug=True)
43 changes: 43 additions & 0 deletions dict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# 创建一个空字典
fruits = {}

# 创建一个包含一些水果及其数量的字典
fruits = {
'apple': 10,
'banana': 5,
'orange': 8
}
# 访问字典中的值
print(fruits['apple']) # 输出: 10
# 添加一个新的键值对
fruits['mango'] = 15

# 更新一个已有的键值对
fruits['banana'] = 7

print(fruits)
# 输出: {'apple': 10, 'banana': 7, 'orange': 8, 'mango': 15}
# 删除一个键值对
del fruits['orange']

print(fruits)
# 输出: {'apple': 10, 'banana': 7, 'mango': 15}

# 遍历字典中的键值对
for fruit, quantity in fruits.items():
print(f"The quantity of {fruit} is {quantity}")

# 检查键是否在字典中
if 'apple' in fruits:
print("Apple is in the dictionary")

if 'grape' not in fruits:
print("Grape is not in the dictionary")

# 获取所有的键
keys = fruits.keys()
print(keys) # 输出: dict_keys(['apple', 'banana', 'mango'])

# 获取所有的值
values = fruits.values()
print(values) # 输出: dict_values([10, 7, 15])
18 changes: 18 additions & 0 deletions students.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "Alice",
"age": 23,
"courses": [
"Math",
"Science"
]
},
{
"name": "Charlie",
"age": 24,
"courses": [
"Art",
"Design"
]
}
]
39 changes: 39 additions & 0 deletions students.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import json

# 读取 JSON 文件
with open('students.json', 'r') as file:
students = json.load(file)

print(students)

# 遍历学生列表
for student in students:
name = student['name']
courses = student['courses']
print(f"Student: {name}")
print("Courses:")
for course in courses:
print(f" - {course}")

# 添加新学生
new_student = {
"name": "Charlie",
"age": 24,
"courses": ["Art", "Design"]
}
students.append(new_student)

# 将更新后的数据写回到 JSON 文件
with open('students.json', 'w') as file:
json.dump(students, file, indent=4)

print("New student added.")

# 删除名为 "Bob" 的学生
students = [student for student in students if student['name'] != 'Bob']

# 将更新后的数据写回到 JSON 文件
with open('students.json', 'w') as file:
json.dump(students, file, indent=4)

print("Student 'Bob' deleted.")
2 changes: 1 addition & 1 deletion templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<header class="App-header">
<img src="{{ url_for('static', filename='Octocat.png') }}" class="App-logo" alt="logo" />
<p>
GitHub Codespaces <span class="heart">♥</span> Flask
GitHub Codespaces <span class="heart">♥️hello wulb</span> Flask
</p>
<p class="small">
Edit <code>templates/index.html</code> and refresh to see your changes!
Expand Down
30 changes: 30 additions & 0 deletions templates/settings.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!DOCTYPE html>
<html>
<head>
<title>API Settings</title>
<link rel="stylesheet" href="{{ url_for('static', filename='main.css') }}">
</head>
<body>
<div class="App">
<header class="App-header">
<h1>API Settings</h1>
<form action="/save_settings" method="post" style="display: flex; flex-direction: column; gap: 10px; text-align: left; width: 300px;">
<div>
<label for="openai_key">OpenAI API Key:</label>
<input type="password" id="openai_key" name="openai_key" value="{{ settings.openai_key if settings else '' }}">
</div>
<div>
<label for="gemini_key">Gemini API Key:</label>
<input type="password" id="gemini_key" name="gemini_key" value="{{ settings.gemini_key if settings else '' }}">
</div>
<div>
<label for="anthropic_key">Anthropic API Key:</label>
<input type="password" id="anthropic_key" name="anthropic_key" value="{{ settings.anthropic_key if settings else '' }}">
</div>
<button type="submit" style="padding: 10px; cursor: pointer;">Save Settings</button>
</form>
<p><a href="/" style="color: #61dafb;">Back to Home</a></p>
</header>
</div>
</body>
</html>