Eluza133 commited on
Commit
a30c72f
·
verified ·
1 Parent(s): a561ca9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -20
app.py CHANGED
@@ -76,7 +76,9 @@ def download_db_from_hf():
76
  logging.info("База данных скачана с Hugging Face")
77
  except Exception as e:
78
  logging.error(f"Ошибка скачивания базы: {e}")
79
- raise
 
 
80
 
81
  def periodic_backup():
82
  while True:
@@ -116,7 +118,7 @@ def register():
116
  button { padding: 10px 20px; background: #3b82f6; color: white; border: none; border-radius: 8px; cursor: pointer; width: 100%; }
117
  .flash { color: red; margin-bottom: 10px; }
118
  @media (max-width: 600px) {
119
- .container { padding: 15px; }
120
  input, button { font-size: 14px; padding: 8px; }
121
  }
122
  </style>
@@ -174,7 +176,7 @@ def login():
174
  button { padding: 10px 20px; background: #3b82f6; color: white; border: none; border-radius: 8px; cursor: pointer; width: 100%; }
175
  .flash { color: red; margin-bottom: 10px; }
176
  @media (max-width: 600px) {
177
- .container { padding: 15px; }
178
  input, button { font-size: 14px; padding: 8px; }
179
  }
180
  </style>
@@ -212,7 +214,7 @@ def logout():
212
  @app.route('/')
213
  def feed():
214
  data = load_data()
215
- posts = data['posts']
216
  is_authenticated = 'username' in session
217
  username = session.get('username', None)
218
  html = '''
@@ -237,13 +239,14 @@ def feed():
237
  .menu-btn { display: none; font-size: 24px; background: none; border: none; cursor: pointer; position: fixed; top: 20px; left: 20px; z-index: 1001; }
238
  .stats { font-size: 0.9em; color: #666; }
239
  @media (max-width: 768px) {
240
- .container { padding-left: 20px; }
241
- .sidebar { left: -220px; }
242
  .sidebar.active { left: 0; }
243
  .menu-btn { display: block; }
244
- .post-grid { grid-template-columns: 1fr; }
245
  .post-item { padding: 10px; }
246
  .post-preview { height: 150px; }
 
247
  }
248
  </style>
249
  </head>
@@ -321,7 +324,9 @@ def post_page(post_id):
321
  if 'like' in request.form:
322
  if username not in post.get('likes', []):
323
  post['likes'] = post.get('likes', []) + [username]
324
- save_data(data)
 
 
325
  elif 'comment' in request.form:
326
  comment_text = request.form.get('comment')
327
  if comment_text:
@@ -341,7 +346,7 @@ def post_page(post_id):
341
  .sidebar { position: fixed; left: -220px; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); transition: left 0.3s; z-index: 1000; }
342
  .sidebar.active { left: 0; }
343
  .container { max-width: 800px; margin: 0 auto; padding-left: 220px; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); transition: padding-left 0.3s; }
344
- video, img { width: 100%; border-radius: 8px; }
345
  .back-btn, .profile-link, .logout-btn, .like-btn { display: inline-block; margin: 10px 0; padding: 10px; background: #3b82f6; color: white; text-decoration: none; border-radius: 8px; border: none; cursor: pointer; }
346
  .profile-link { background: #10b981; }
347
  .logout-btn { background: #ef4444; }
@@ -350,12 +355,13 @@ def post_page(post_id):
350
  textarea { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #e2e8f0; border-radius: 8px; }
351
  .comment { border-top: 1px solid #e2e8f0; padding: 10px 0; }
352
  @media (max-width: 768px) {
353
- .container { padding-left: 20px; padding: 15px; }
354
- .sidebar { left: -220px; }
355
  .sidebar.active { left: 0; }
356
  .menu-btn { display: block; }
357
- video, img { height: auto; }
358
- .back-btn, .like-btn { width: 100%; text-align: center; }
 
359
  }
360
  </style>
361
  </head>
@@ -458,14 +464,15 @@ def profile():
458
  .menu-btn { display: none; font-size: 24px; background: none; border: none; cursor: pointer; position: fixed; top: 20px; left: 20px; z-index: 1001; }
459
  .stats { font-size: 0.9em; color: #666; }
460
  @media (max-width: 768px) {
461
- .container { padding-left: 20px; }
462
- .sidebar { left: -220px; }
463
  .sidebar.active { left: 0; }
464
  .menu-btn { display: block; }
465
- .post-grid { grid-template-columns: 1fr; }
466
  .post-item { padding: 10px; }
467
  .post-preview { height: 150px; }
468
- .upload-btn, .delete-btn { font-size: 14px; padding: 8px; }
 
469
  }
470
  </style>
471
  </head>
@@ -614,11 +621,14 @@ def upload():
614
  .logout-btn { background: #ef4444; }
615
  .menu-btn { display: none; font-size: 24px; background: none; border: none; cursor: pointer; position: fixed; top: 20px; left: 20px; z-index: 1001; }
616
  @media (max-width: 768px) {
617
- .container { padding-left: 20px; padding: 15px; }
618
- .sidebar { left: -220px; }
619
  .sidebar.active { left: 0; }
620
  .menu-btn { display: block; }
621
- input, textarea, button { font-size: 14px; padding: 8px; }
 
 
 
622
  }
623
  </style>
624
  </head>
 
76
  logging.info("База данных скачана с Hugging Face")
77
  except Exception as e:
78
  logging.error(f"Ошибка скачивания базы: {e}")
79
+ if not os.path.exists(DATA_FILE):
80
+ with open(DATA_FILE, 'w', encoding='utf-8') as f:
81
+ json.dump({'posts': [], 'users': {}}, f)
82
 
83
  def periodic_backup():
84
  while True:
 
118
  button { padding: 10px 20px; background: #3b82f6; color: white; border: none; border-radius: 8px; cursor: pointer; width: 100%; }
119
  .flash { color: red; margin-bottom: 10px; }
120
  @media (max-width: 600px) {
121
+ .container { padding: 15px; max-width: 100%; }
122
  input, button { font-size: 14px; padding: 8px; }
123
  }
124
  </style>
 
176
  button { padding: 10px 20px; background: #3b82f6; color: white; border: none; border-radius: 8px; cursor: pointer; width: 100%; }
177
  .flash { color: red; margin-bottom: 10px; }
178
  @media (max-width: 600px) {
179
+ .container { padding: 15px; max-width: 100%; }
180
  input, button { font-size: 14px; padding: 8px; }
181
  }
182
  </style>
 
214
  @app.route('/')
215
  def feed():
216
  data = load_data()
217
+ posts = data.get('posts', [])
218
  is_authenticated = 'username' in session
219
  username = session.get('username', None)
220
  html = '''
 
239
  .menu-btn { display: none; font-size: 24px; background: none; border: none; cursor: pointer; position: fixed; top: 20px; left: 20px; z-index: 1001; }
240
  .stats { font-size: 0.9em; color: #666; }
241
  @media (max-width: 768px) {
242
+ .container { padding-left: 20px; padding: 10px; }
243
+ .sidebar { left: -220px; width: 150px; padding: 15px; }
244
  .sidebar.active { left: 0; }
245
  .menu-btn { display: block; }
246
+ .post-grid { grid-template-columns: 1fr; gap: 15px; }
247
  .post-item { padding: 10px; }
248
  .post-preview { height: 150px; }
249
+ .auth-links, .upload-btn, .logout-btn, .profile-link { font-size: 14px; padding: 8px; }
250
  }
251
  </style>
252
  </head>
 
324
  if 'like' in request.form:
325
  if username not in post.get('likes', []):
326
  post['likes'] = post.get('likes', []) + [username]
327
+ else:
328
+ post['likes'] = [user for user in post.get('likes', []) if user != username]
329
+ save_data(data)
330
  elif 'comment' in request.form:
331
  comment_text = request.form.get('comment')
332
  if comment_text:
 
346
  .sidebar { position: fixed; left: -220px; top: 0; width: 200px; height: 100%; background: #fff; padding: 20px; box-shadow: 2px 0 5px rgba(0,0,0,0.1); transition: left 0.3s; z-index: 1000; }
347
  .sidebar.active { left: 0; }
348
  .container { max-width: 800px; margin: 0 auto; padding-left: 220px; background: #fff; padding: 20px; border-radius: 10px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); transition: padding-left 0.3s; }
349
+ video, img { width: 100%; border-radius: 8px; max-height: 400px; object-fit: cover; }
350
  .back-btn, .profile-link, .logout-btn, .like-btn { display: inline-block; margin: 10px 0; padding: 10px; background: #3b82f6; color: white; text-decoration: none; border-radius: 8px; border: none; cursor: pointer; }
351
  .profile-link { background: #10b981; }
352
  .logout-btn { background: #ef4444; }
 
355
  textarea { width: 100%; padding: 10px; margin: 10px 0; border: 1px solid #e2e8f0; border-radius: 8px; }
356
  .comment { border-top: 1px solid #e2e8f0; padding: 10px 0; }
357
  @media (max-width: 768px) {
358
+ .container { padding-left: 20px; padding: 15px; max-width: 100%; }
359
+ .sidebar { left: -220px; width: 150px; padding: 15px; }
360
  .sidebar.active { left: 0; }
361
  .menu-btn { display: block; }
362
+ video, img { max-height: 250px; }
363
+ .back-btn, .like-btn, textarea, button { width: 100%; font-size: 14px; padding: 8px; margin: 5px 0; }
364
+ h1 { font-size: 1.2em; }
365
  }
366
  </style>
367
  </head>
 
464
  .menu-btn { display: none; font-size: 24px; background: none; border: none; cursor: pointer; position: fixed; top: 20px; left: 20px; z-index: 1001; }
465
  .stats { font-size: 0.9em; color: #666; }
466
  @media (max-width: 768px) {
467
+ .container { padding-left: 20px; padding: 15px; max-width: 100%; }
468
+ .sidebar { left: -220px; width: 150px; padding: 15px; }
469
  .sidebar.active { left: 0; }
470
  .menu-btn { display: block; }
471
+ .post-grid { grid-template-columns: 1fr; gap: 15px; }
472
  .post-item { padding: 10px; }
473
  .post-preview { height: 150px; }
474
+ .upload-btn, .delete-btn, .profile-link, .logout-btn { font-size: 14px; padding: 8px; }
475
+ h1, h2 { font-size: 1.2em; }
476
  }
477
  </style>
478
  </head>
 
621
  .logout-btn { background: #ef4444; }
622
  .menu-btn { display: none; font-size: 24px; background: none; border: none; cursor: pointer; position: fixed; top: 20px; left: 20px; z-index: 1001; }
623
  @media (max-width: 768px) {
624
+ .container { padding-left: 20px; padding: 15px; max-width: 100%; }
625
+ .sidebar { left: -220px; width: 150px; padding: 15px; }
626
  .sidebar.active { left: 0; }
627
  .menu-btn { display: block; }
628
+ input, textarea, button { font-size: 14px; padding: 8px; margin: 5px 0; }
629
+ h1 { font-size: 1.2em; }
630
+ #progress-container { height: 15px; }
631
+ #progress-bar { height: 15px; }
632
  }
633
  </style>
634
  </head>