-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.py
More file actions
558 lines (525 loc) ยท 15.2 KB
/
Copy pathapp.py
File metadata and controls
558 lines (525 loc) ยท 15.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
from flask import Flask, render_template, jsonify
import sqlite3
from datetime import datetime
import os
import random # Add import for random selection
app = Flask(__name__)
# Use Azure's writable directory if available, otherwise use local path
if 'WEBSITE_SITE_NAME' in os.environ:
DB_PATH = os.path.join('/home/data', 'emoji_stats.db')
else:
DB_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'emoji_stats.db')
# Ensure the directory exists
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
# Manual emoji dictionary
EMOJIS = {
# Faces and Expressions
"smiling face": "๐",
"grinning face": "๐",
"laughing face": "๐",
"rolling on floor": "๐คฃ",
"winking face": "๐",
"heart eyes": "๐",
"star struck": "๐คฉ",
"thinking face": "๐ค",
"mind blown": "๐คฏ",
"cool face": "๐",
"nerd face": "๐ค",
"crying face": "๐ข",
"loudly crying": "๐ญ",
"shocked face": "๐ฑ",
"sleeping face": "๐ด",
"drooling face": "๐คค",
"zany face": "๐คช",
"partying face": "๐ฅณ",
"smirking face": "๐",
"unamused face": "๐",
"rolling eyes": "๐",
"angry face": "๐ ",
"devil": "๐",
"angel": "๐",
# Gestures and People
"thumbs up": "๐",
"thumbs down": "๐",
"clapping hands": "๐",
"raised hands": "๐",
"folded hands": "๐",
"handshake": "๐ค",
"victory hand": "โ๏ธ",
"love you gesture": "๐ค",
"crossed fingers": "๐ค",
"waving hand": "๐",
"muscle": "๐ช",
"ninja": "๐ฅท",
"person dancing": "๐",
"person running": "๐",
# Hearts and Emotions
"red heart": "โค๏ธ",
"orange heart": "๐งก",
"yellow heart": "๐",
"green heart": "๐",
"blue heart": "๐",
"purple heart": "๐",
"broken heart": "๐",
"sparkling heart": "๐",
"hundred points": "๐ฏ",
# Animals
"cat": "๐ฑ",
"dog": "๐ถ",
"monkey": "๐",
"unicorn": "๐ฆ",
"panda": "๐ผ",
"penguin": "๐ง",
"koala": "๐จ",
"lion": "๐ฆ",
"tiger": "๐ฏ",
"cow": "๐ฎ",
"pig": "๐ท",
"frog": "๐ธ",
"octopus": "๐",
"butterfly": "๐ฆ",
# Food and Drink
"pizza": "๐",
"burger": "๐",
"fries": "๐",
"hotdog": "๐ญ",
"taco": "๐ฎ",
"sushi": "๐ฃ",
"ice cream": "๐ฆ",
"donut": "๐ฉ",
"cake": "๐",
"coffee": "โ",
"beer": "๐บ",
"wine": "๐ท",
# Activities and Objects
"soccer ball": "โฝ",
"basketball": "๐",
"football": "๐",
"tennis": "๐พ",
"volleyball": "๐",
"musical note": "๐ต",
"headphones": "๐ง",
"guitar": "๐ธ",
"camera": "๐ท",
"movie camera": "๐ฅ",
"game die": "๐ฒ",
"jigsaw": "๐งฉ",
"art": "๐จ",
"microphone": "๐ค",
# Nature and Weather
"fire": "๐ฅ",
"rainbow": "๐",
"sun": "โ๏ธ",
"moon": "๐",
"cloud": "โ๏ธ",
"lightning": "โก",
"umbrella": "โ",
"snowflake": "โ๏ธ",
"palm tree": "๐ด",
"christmas tree": "๐",
"flower": "๐ธ",
"four leaf clover": "๐",
# Country Flags
"afghanistan": "๐ฆ๐ซ",
"albania": "๐ฆ๐ฑ",
"algeria": "๐ฉ๐ฟ",
"andorra": "๐ฆ๐ฉ",
"angola": "๐ฆ๐ด",
"antigua & barbuda": "๐ฆ๐ฌ",
"argentina": "๐ฆ๐ท",
"armenia": "๐ฆ๐ฒ",
"australia": "๐ฆ๐บ",
"austria": "๐ฆ๐น",
"azerbaijan": "๐ฆ๐ฟ",
"bahamas": "๐ง๐ธ",
"bahrain": "๐ง๐ญ",
"bangladesh": "๐ง๐ฉ",
"barbados": "๐ง๐ง",
"belarus": "๐ง๐พ",
"belgium": "๐ง๐ช",
"belize": "๐ง๐ฟ",
"benin": "๐ง๐ฏ",
"bhutan": "๐ง๐น",
"bolivia": "๐ง๐ด",
"bosnia & herzegovina": "๐ง๐ฆ",
"botswana": "๐ง๐ผ",
"brazil": "๐ง๐ท",
"brunei": "๐ง๐ณ",
"bulgaria": "๐ง๐ฌ",
"burkina faso": "๐ง๐ซ",
"burundi": "๐ง๐ฎ",
"cabo verde": "๐จ๐ป",
"cambodia": "๐ฐ๐ญ",
"cameroon": "๐จ๐ฒ",
"canada": "๐จ๐ฆ",
"central african republic": "๐จ๐ซ",
"chad": "๐น๐ฉ",
"chile": "๐จ๐ฑ",
"china": "๐จ๐ณ",
"colombia": "๐จ๐ด",
"comoros": "๐ฐ๐ฒ",
"congo - brazzaville": "๐จ๐ฌ",
"congo - kinshasa": "๐จ๐ฉ",
"costa rica": "๐จ๐ท",
"croatia": "๐ญ๐ท",
"cuba": "๐จ๐บ",
"cyprus": "๐จ๐พ",
"czechia": "๐จ๐ฟ",
"denmark": "๐ฉ๐ฐ",
"djibouti": "๐ฉ๐ฏ",
"dominica": "๐ฉ๐ฒ",
"dominican republic": "๐ฉ๐ด",
"ecuador": "๐ช๐จ",
"egypt": "๐ช๐ฌ",
"el salvador": "๐ธ๐ป",
"equatorial guinea": "๐ฌ๐ถ",
"eritrea": "๐ช๐ท",
"estonia": "๐ช๐ช",
"eswatini": "๐ธ๐ฟ",
"ethiopia": "๐ช๐น",
"fiji": "๐ซ๐ฏ",
"finland": "๐ซ๐ฎ",
"france": "๐ซ๐ท",
"gabon": "๐ฌ๐ฆ",
"gambia": "๐ฌ๐ฒ",
"georgia": "๐ฌ๐ช",
"germany": "๐ฉ๐ช",
"ghana": "๐ฌ๐ญ",
"greece": "๐ฌ๐ท",
"grenada": "๐ฌ๐ฉ",
"guatemala": "๐ฌ๐น",
"guinea": "๐ฌ๐ณ",
"guinea-bissau": "๐ฌ๐ผ",
"guyana": "๐ฌ๐พ",
"haiti": "๐ญ๐น",
"honduras": "๐ญ๐ณ",
"hungary": "๐ญ๐บ",
"iceland": "๐ฎ๐ธ",
"india": "๐ฎ๐ณ",
"indonesia": "๐ฎ๐ฉ",
"iran": "๐ฎ๐ท",
"iraq": "๐ฎ๐ถ",
"ireland": "๐ฎ๐ช",
"israel": "๐ฎ๐ฑ",
"italy": "๐ฎ๐น",
"jamaica": "๐ฏ๐ฒ",
"japan": "๐ฏ๐ต",
"jordan": "๐ฏ๐ด",
"kazakhstan": "๐ฐ๐ฟ",
"kenya": "๐ฐ๐ช",
"kiribati": "๐ฐ๐ฎ",
"kosovo": "๐ฝ๐ฐ",
"kuwait": "๐ฐ๐ผ",
"kyrgyzstan": "๐ฐ๐ฌ",
"laos": "๐ฑ๐ฆ",
"latvia": "๐ฑ๐ป",
"lebanon": "๐ฑ๐ง",
"lesotho": "๐ฑ๐ธ",
"liberia": "๐ฑ๐ท",
"libya": "๐ฑ๐พ",
"liechtenstein": "๐ฑ๐ฎ",
"lithuania": "๐ฑ๐น",
"luxembourg": "๐ฑ๐บ",
"madagascar": "๐ฒ๐ฌ",
"malawi": "๐ฒ๐ผ",
"malaysia": "๐ฒ๐พ",
"maldives": "๐ฒ๐ป",
"mali": "๐ฒ๐ฑ",
"malta": "๐ฒ๐น",
"marshall islands": "๐ฒ๐ญ",
"mauritania": "๐ฒ๐ท",
"mauritius": "๐ฒ๐บ",
"mexico": "๐ฒ๐ฝ",
"micronesia": "๐ซ๐ฒ",
"moldova": "๐ฒ๐ฉ",
"monaco": "๐ฒ๐จ",
"mongolia": "๐ฒ๐ณ",
"montenegro": "๐ฒ๐ช",
"morocco": "๐ฒ๐ฆ",
"mozambique": "๐ฒ๐ฟ",
"myanmar": "๐ฒ๐ฒ",
"namibia": "๐ณ๐ฆ",
"nauru": "๐ณ๐ท",
"nepal": "๐ณ๐ต",
"netherlands": "๐ณ๐ฑ",
"new zealand": "๐ณ๐ฟ",
"nicaragua": "๐ณ๐ฎ",
"niger": "๐ณ๐ช",
"nigeria": "๐ณ๐ฌ",
"north korea": "๐ฐ๐ต",
"north macedonia": "๐ฒ๐ฐ",
"norway": "๐ณ๐ด",
"oman": "๐ด๐ฒ",
"pakistan": "๐ต๐ฐ",
"palau": "๐ต๐ผ",
"palestinian territories": "๐ต๐ธ",
"panama": "๐ต๐ฆ",
"papua new guinea": "๐ต๐ฌ",
"paraguay": "๐ต๐พ",
"peru": "๐ต๐ช",
"philippines": "๐ต๐ญ",
"poland": "๐ต๐ฑ",
"portugal": "๐ต๐น",
"qatar": "๐ถ๐ฆ",
"romania": "๐ท๐ด",
"russia": "๐ท๐บ",
"rwanda": "๐ท๐ผ",
"saint kitts & nevis": "๐ฐ๐ณ",
"saint lucia": "๐ฑ๐จ",
"saint vincent & grenadines": "๐ป๐จ",
"samoa": "๐ผ๐ธ",
"san marino": "๐ธ๐ฒ",
"sao tome & principe": "๐ธ๐น",
"saudi arabia": "๐ธ๐ฆ",
"senegal": "๐ธ๐ณ",
"serbia": "๐ท๐ธ",
"seychelles": "๐ธ๐จ",
"sierra leone": "๐ธ๐ฑ",
"singapore": "๐ธ๐ฌ",
"slovakia": "๐ธ๐ฐ",
"slovenia": "๐ธ๐ฎ",
"solomon islands": "๐ธ๐ง",
"somalia": "๐ธ๐ด",
"south africa": "๐ฟ๐ฆ",
"south korea": "๐ฐ๐ท",
"south sudan": "๐ธ๐ธ",
"spain": "๐ช๐ธ",
"sri lanka": "๐ฑ๐ฐ",
"sudan": "๐ธ๐ฉ",
"suriname": "๐ธ๐ท",
"sweden": "๐ธ๐ช",
"switzerland": "๐จ๐ญ",
"syria": "๐ธ๐พ",
"taiwan": "๐น๐ผ",
"tajikistan": "๐น๐ฏ",
"tanzania": "๐น๐ฟ",
"thailand": "๐น๐ญ",
"timor-leste": "๐น๐ฑ",
"togo": "๐น๐ฌ",
"tonga": "๐น๐ด",
"trinidad & tobago": "๐น๐น",
"tunisia": "๐น๐ณ",
"turkey": "๐น๐ท",
"turkmenistan": "๐น๐ฒ",
"tuvalu": "๐น๐ป",
"uganda": "๐บ๐ฌ",
"ukraine": "๐บ๐ฆ",
"united arab emirates": "๐ฆ๐ช",
"united kingdom": "๐ฌ๐ง",
"united states": "๐บ๐ธ",
"uruguay": "๐บ๐พ",
"uzbekistan": "๐บ๐ฟ",
"vanuatu": "๐ป๐บ",
"vatican city": "๐ป๐ฆ",
"venezuela": "๐ป๐ช",
"vietnam": "๐ป๐ณ",
"yemen": "๐พ๐ช",
"zambia": "๐ฟ๐ฒ",
"zimbabwe": "๐ฟ๐ผ",
# Other flags
"rainbow flag": "๐ณ๏ธโ๐",
"transgender flag": "๐ณ๏ธโโง๏ธ",
"white flag": "๐ณ๏ธ",
"black flag": "๐ด",
"pirate flag": "๐ดโโ ๏ธ",
"united nations": "๐บ๐ณ",
"european union": "๐ช๐บ",
"checkered flag": "๐",
"triangular flag": "๐ฉ",
# Flags
"flag argentina": "๐ฆ๐ท",
"flag australia": "๐ฆ๐บ",
"flag austria": "๐ฆ๐น",
"flag belgium": "๐ง๐ช",
"flag brazil": "๐ง๐ท",
"flag canada": "๐จ๐ฆ",
"flag chile": "๐จ๐ฑ",
"flag china": "๐จ๐ณ",
"flag colombia": "๐จ๐ด",
"flag denmark": "๐ฉ๐ฐ",
"flag egypt": "๐ช๐ฌ",
"flag finland": "๐ซ๐ฎ",
"flag france": "๐ซ๐ท",
"flag germany": "๐ฉ๐ช",
"flag greece": "๐ฌ๐ท",
"flag hong kong": "๐ญ๐ฐ",
"flag iceland": "๐ฎ๐ธ",
"flag india": "๐ฎ๐ณ",
"flag indonesia": "๐ฎ๐ฉ",
"flag ireland": "๐ฎ๐ช",
"flag israel": "๐ฎ๐ฑ",
"flag italy": "๐ฎ๐น",
"flag japan": "๐ฏ๐ต",
"flag malaysia": "๐ฒ๐พ",
"flag mexico": "๐ฒ๐ฝ",
"flag morocco": "๐ฒ๐ฆ",
"flag netherlands": "๐ณ๐ฑ",
"flag new zealand": "๐ณ๐ฟ",
"flag nigeria": "๐ณ๐ฌ",
"flag norway": "๐ณ๐ด",
"flag pakistan": "๐ต๐ฐ",
"flag philippines": "๐ต๐ญ",
"flag poland": "๐ต๐ฑ",
"flag portugal": "๐ต๐น",
"flag russia": "๐ท๐บ",
"flag saudi arabia": "๐ธ๐ฆ",
"flag singapore": "๐ธ๐ฌ",
"flag south africa": "๐ฟ๐ฆ",
"flag south korea": "๐ฐ๐ท",
"flag spain": "๐ช๐ธ",
"flag sweden": "๐ธ๐ช",
"flag switzerland": "๐จ๐ญ",
"flag taiwan": "๐น๐ผ",
"flag thailand": "๐น๐ญ",
"flag turkey": "๐น๐ท",
"flag uk": "๐ฌ๐ง",
"flag ukraine": "๐บ๐ฆ",
"flag usa": "๐บ๐ธ",
"flag vietnam": "๐ป๐ณ",
# Other
"rocket": "๐",
"star": "โญ",
"sparkles": "โจ",
"party popper": "๐",
"gift": "๐",
"ghost": "๐ป",
"alien": "๐ฝ",
"robot": "๐ค",
"poop": "๐ฉ",
"money bag": "๐ฐ",
"gem stone": "๐",
"warning": "โ ๏ธ",
"light bulb": "๐ก",
"lock": "๐",
"key": "๐",
"magnifying glass": "๐",
"alarm clock": "โฐ",
"hourglass": "โ",
"battery": "๐",
"books": "๐"
}
# Database initialization
def init_db():
conn = sqlite3.connect(DB_PATH)
c = conn.cursor()
# Create table for emoji usage counts
c.execute('''
CREATE TABLE IF NOT EXISTS emoji_counts (
emoji_name TEXT PRIMARY KEY,
copy_count INTEGER DEFAULT 0,
api_count INTEGER DEFAULT 0,
last_used TIMESTAMP
)
''')
# Create table for usage history
c.execute('''
CREATE TABLE IF NOT EXISTS usage_history (
id INTEGER PRIMARY KEY AUTOINCREMENT,
emoji_name TEXT,
usage_type TEXT,
timestamp TIMESTAMP,
FOREIGN KEY (emoji_name) REFERENCES emoji_counts (emoji_name)
)
''')
# Initialize counts for all emojis if they don't exist
for emoji_name in EMOJIS.keys():
c.execute('INSERT OR IGNORE INTO emoji_counts (emoji_name, copy_count, api_count) VALUES (?, 0, 0)', (emoji_name,))
conn.commit()
conn.close()
# Initialize database on app startup
init_db()
def get_emoji_counts():
conn = sqlite3.connect(DB_PATH)
c = conn.cursor()
c.execute('SELECT emoji_name, copy_count + api_count as total_count FROM emoji_counts')
counts = {row[0]: row[1] for row in c.fetchall()}
conn.close()
return counts
def increment_count(emoji_name, usage_type):
conn = sqlite3.connect(DB_PATH)
c = conn.cursor()
if usage_type == 'copy':
c.execute('UPDATE emoji_counts SET copy_count = copy_count + 1, last_used = ? WHERE emoji_name = ?',
(datetime.now(), emoji_name))
else: # api
c.execute('UPDATE emoji_counts SET api_count = api_count + 1, last_used = ? WHERE emoji_name = ?',
(datetime.now(), emoji_name))
# Record in history
c.execute('INSERT INTO usage_history (emoji_name, usage_type, timestamp) VALUES (?, ?, ?)',
(emoji_name, usage_type, datetime.now()))
conn.commit()
# Get updated count
if usage_type == 'copy':
c.execute('SELECT copy_count FROM emoji_counts WHERE emoji_name = ?', (emoji_name,))
else:
c.execute('SELECT api_count FROM emoji_counts WHERE emoji_name = ?', (emoji_name,))
count = c.fetchone()[0]
conn.close()
return count
def get_all_emojis():
return EMOJIS
@app.route('/')
def index():
emojis = get_all_emojis()
counts = get_emoji_counts()
# Sort emojis by total usage count (descending)
sorted_emojis = dict(sorted(emojis.items(), key=lambda x: counts.get(x[0], 0), reverse=True))
return render_template('index.html', emojis=sorted_emojis, counts=counts)
@app.route('/api/emoji/<emoji_name>')
def get_emoji(emoji_name):
emojis = get_all_emojis()
if emoji_name in emojis:
count = increment_count(emoji_name, 'api')
return jsonify({
'emoji': emojis[emoji_name],
'name': emoji_name,
'count': count
})
return jsonify({'error': 'Emoji not found'}), 404
@app.route('/api/increment/<emoji_name>')
def increment_emoji_count(emoji_name):
emojis = get_all_emojis()
if emoji_name in emojis:
count = increment_count(emoji_name, 'copy')
return jsonify({
'success': True,
'count': count
})
return jsonify({'error': 'Emoji not found'}), 404
@app.route('/api/stats')
def get_stats():
conn = sqlite3.connect(DB_PATH)
c = conn.cursor()
c.execute('''
SELECT
emoji_name,
copy_count,
api_count,
last_used
FROM emoji_counts
ORDER BY (copy_count + api_count) DESC
LIMIT 10
''')
top_emojis = [{
'emoji': EMOJIS[row[0]],
'name': row[0],
'copy_count': row[1],
'api_count': row[2],
'last_used': row[3]
} for row in c.fetchall()]
conn.close()
return jsonify(top_emojis)
@app.route('/api/random')
def get_random_emoji():
emoji_name = random.choice(list(EMOJIS.keys()))
count = increment_count(emoji_name, 'api')
return jsonify({
'emoji': EMOJIS[emoji_name],
'name': emoji_name,
'count': count
})
@app.route('/api-docs')
def api_docs():
return render_template('api.html')
if __name__ == '__main__':
app.run(debug=True)