-
Notifications
You must be signed in to change notification settings - Fork 20
/
main.py
1615 lines (1326 loc) · 62.6 KB
/
main.py
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
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import flet as ft
from flet import Page, Text, Row, TextField, ElevatedButton, Checkbox, Column, Container, IconButton, Theme
import time
from time import sleep
import requests
import io
from io import open
import webbrowser
import pandas as pd
from pandas import ExcelWriter
from datetime import datetime
from multiprocessing import Process
import search_products
import publish
from os import remove
# Starting the scripts that will search for products on Amazon and post on Telegram.
def script_search_products():
search_products.enable(True)
def script_publish():
publish.enable(True)
if __name__ == '__main__':
processes_search_product = []
processes_publish_product = []
for i in range(0, 500):
processes_search_product.append(Process(target=script_search_products))
processes_publish_product.append(Process(target=script_publish))
# thread_search_product = Process(target=script_search_products)
# thread_publish_product = Process(target=script_publish)
def main(page: ft.Page):
# Defining the program title and design
page.window_maximizable = True
page.title = "Amacapy 2.0"
page.vertical_alignment = "center"
page.horizontal_alignment = "center"
page.window_width = 720
page.window_height = 680
page.window_resizable = True
page.theme_mode = ft.ThemeMode.DARK
title_amacapy = Text(
value="Amacapy",
size=30,
color="white",
weight="bold",
italic=True,
)
page.add(title_amacapy)
def main_interface():
# This function will display the screen with the list of products that will be ready to be published.
def page_publish(self):
try:
# We read the file where the product data is stored
verify_list_publish = pd.read_excel('data/list_publish.xlsx', header = 0)
except:
sleep(2)
try:
# We read the file where the product data is stored
verify_list_publish = pd.read_excel('data/list_publish.xlsx', header = 0)
except:
remove('data/list_publish.xlsx')
update_list_publish_data = pd.DataFrame(columns = ['title', 'price', 'currency', 'url'])
with ExcelWriter('data/list_publish.xlsx') as writer:
update_list_publish_data.to_excel(writer, 'Sheet', index=False)
title_list_publish = verify_list_publish['title'].values
price_list_publish = verify_list_publish['price'].values
currency_list_publish = verify_list_publish['currency'].values
url_list_publish = verify_list_publish['url'].values
# Title that will appear in the publish products view.
title_head_list_publish = Text(
value="Products to Publish",
size=20,
color="white",
weight="bold",
italic=True,
)
all_results = ft.Column(scroll="always", expand=True)
# The file is checked for stored data to be able to display it on the screen.
if len(verify_list_publish) > 0:
currency = f"({currency_list_publish[0]})"
for i in range(len(verify_list_publish)):
all_results.controls.append(
ft.Row(spacing=28, run_spacing=5, controls=[
Text(f"{i+1}. "),
ft.IconButton(on_click=view_url_list_publish, data = i, icon="remove_red_eye_rounded", icon_size=20),
ft.TextField(value=title_list_publish[i], label = i, on_blur=change_title_publish, text_align="start", keyboard_type = "text", width=250, height = 50, text_size=12, content_padding = 10),
ft.TextField(value=price_list_publish[i], label = i, on_blur=change_price_publish, text_align="start", keyboard_type = "number", width=70, height = 50, text_size=12, content_padding = 10),
ft.IconButton(on_click=delete_product_button, data = i, icon="delete_forever_rounded", icon_size=20),
], alignment="center", vertical_alignment = "center")
)
# If the file has no data, then a message that there are no products is displayed.
else:
currency = ''
all_results.controls.append(
ft.Row(spacing=40, run_spacing=10, controls=[
Text("You have not yet added articles for publication")
], alignment="center", vertical_alignment = "center")
)
page.clean() # We clean the screen before adding a new one.
page.add(
ft.Container(height = 50, content= title_head_list_publish, alignment=ft.alignment.center),
ft.Divider(height=1, color="black"),
ft.Row(spacing=1, controls=[
Text('N°', color="white", width=55, text_align="center"),
Text('View', color="white", width=60, text_align="center"),
Text('Product Title', color="white", width=290, text_align="center"),
Text(f'Price {currency}', color="white", width=80, text_align="center"),
Text('Del',width=80, text_align="center", color="white"),
],
alignment="center", vertical_alignment = "center"),
ft.Divider(height=1, color="black"),
ft.Container(width= 650, height= 348, content=all_results),
ft.Container(width= 650, height= 40, content=ft.Row(controls=[
ft.ElevatedButton("Delete All", icon="delete_rounded", on_click=delete_all_products_publish)
],
alignment="end", vertical_alignment = "start")
),
ft.Row(controls=[
Text('Publish every', width=90, text_align="start",color="white"),
minutes_publish,
Text('on', width=20, text_align="start", color="white"),
ft.ElevatedButton('Telegram' ,icon="telegram_rounded", on_click=publish_on_telegram),
],
alignment="center", vertical_alignment = "center"),
ft.Container(content= ft.Row(controls=list_all_button_menu,
alignment="center", vertical_alignment = "end"),
height = 50
)
)
# The same process is repeated as in the page_publish function
# But in this case to see the history of published products.
def page_history(self):
# The file that stores the history of published products is read.
verify_history = pd.read_excel('data/history.xlsx', header = 0)
date_history = verify_history['date'].values
title_history = verify_history['title'].values
price_history = verify_history['price'].values
url_history = verify_history['url'].values
platform_history = verify_history['platform'].values
# Title that will appear in the history view.
title_list_history = Text(
value="History of published products",
size=20,
color="white",
weight="bold",
italic=True,
)
all_results = ft.Column(scroll="always", expand=True)
# The file is checked for stored data to be able to display it on the screen.
if len(verify_history) > 0:
for i in range(len(verify_history)):
new_date = date_history[i]
new_date = pd.to_datetime(new_date)
new_date = datetime.strftime(new_date, '%Y-%m-%d')
all_results.controls.append(
ft.Row(spacing=28, run_spacing=5, controls=[
Text(f"{i+1}. "),
ft.IconButton(on_click=view_url_history, data = i, icon="remove_red_eye_rounded", icon_size=20),
ft.TextField(value=title_history[i], read_only = True, text_align="start", keyboard_type = "text", width=250, height = 50, text_size=12, content_padding = 10),
ft.Text(color="white", value=price_history[i], width=80, text_align="center"),
ft.Text(color="white", value=platform_history[i]),
ft.Text(color="white", value=new_date)
], alignment="center", vertical_alignment = "center")
)
# If the file has no data, then a message that there are no products is displayed.
else:
currency = ''
all_results.controls.append(
ft.Row(spacing=40, run_spacing=10, controls=[
Text("You have not yet added articles for publication", color="white")
], alignment="center", vertical_alignment = "center")
)
# The view is cleaned before adding another one.
page.clean()
page.add(
ft.Container(height = 50, content= title_list_history, alignment=ft.alignment.center),
ft.Divider(height=1, color="black"),
ft.Row(spacing=10, controls=[
Text('N°', width=20, text_align="center", color="white"),
Text('View', width=80, text_align="center", color="white"),
Text('Product Title', width=270, text_align="center", color="white"),
Text(f'Price', width=95, text_align="center", color="white"),
Text(f'Platform', width=65, text_align="center",color="white"),
Text(f'Date', width=100, text_align="center", color="white")
],
alignment="center", vertical_alignment = "center"),
ft.Divider(height=1, color="black"),
ft.Container(width= 710, height= 408, content=all_results),
ft.Container(width= 710, height= 40, content=ft.Row(controls=[
ft.ElevatedButton("Delete All", icon="delete_rounded", on_click=delete_all_history)
],
alignment="end", vertical_alignment = "start")
),
ft.Container(content= ft.Row(controls=list_all_button_menu,
alignment="center", vertical_alignment = "end"),
height = 50
)
)
# Function to stop the publication of products
def stop_publish_on(e):
# To read the data contained in the file that stores the products to be published.
verify_publish_on = pd.read_excel('data/publish_on.xlsx', header = 0)
# To remove the data from the file of the products to be published.
update_publish_on = pd.DataFrame(columns = ['title', 'price', 'url', 'min', 'telegram'])
# This loop will check if the file still has data. If it has data, it will proceed to delete it.
while len(verify_publish_on) !=0:
try:
with ExcelWriter('data/publish_on.xlsx') as writer:
update_publish_on.to_excel(writer, 'Sheet', index=False)
processes_publish_product[0].kill()
processes_publish_product.pop(0)
except Exception as e:
print('Error: ' + str(e))
sleep(1)
with ExcelWriter('data/publish_on.xlsx') as writer:
update_publish_on.to_excel(writer, 'Sheet', index=False)
processes_publish_product[0].kill()
processes_publish_product.pop(0)
# The file is rechecked to see if it still has data.
verify_publish_on = pd.read_excel('data/publish_on.xlsx', header = 0)
sleep(1)
# The function that displays the products to be published is called
page_publish(1)
# This function will show when products are being published.
def page_publish_on(e):
# To read the data contained in the file that stores the products to be published.
verify_publish_on = pd.read_excel('data/publish_on.xlsx', header = 0)
if len(verify_publish_on) == 0:
pass
else:
processes_publish_product[0].start()
page.clean()
# Text that will display the message "Publishing products..."
publish_text = Text(
value=f"Publishing products...",
size=15,
color="white",
italic=False,
)
# Text with the number of products still to be released
yet_publish_text = Text(
value=f"{len(verify_publish_on)} to publish",
size=15,
color="white",
italic=False,
)
page.add(
ft.Container(content= ft.Column(controls=[
ft.Row(alignment="center", controls=[publish_text]),
yet_publish_text,
press_button_publish_on_stop
], horizontal_alignment = "center", alignment="center"),
height= 520
),
ft.Container(content= ft.Row(controls=list_all_button_menu,
alignment="center", vertical_alignment = "end"),
height = 100
)
)
# As long as there are products to be published, the screen will be updated.
while len(verify_publish_on) !=0 and processes_publish_product[0].is_alive():
verify_publish_on = pd.read_excel('data/publish_on.xlsx', header = 0)
publish_text = Text(
value=f"Publishing products...",
size=15,
color="white",
italic=False,
)
yet_publish_text = Text(
value=f"{len(verify_publish_on)} to publish",
size=15,
color="white",
italic=False,
)
page.clean()
page.add(
ft.Container(content= ft.Column(controls=[
ft.Row(alignment="center", controls=[publish_text]),
yet_publish_text,
press_button_publish_on_stop
], horizontal_alignment = "center", alignment="center"),
height= 520
),
ft.Container(content= ft.Row(controls=list_all_button_menu,
alignment="center", vertical_alignment = "end"),
height = 100
)
)
sleep(5)
verify_publish_on = pd.read_excel('data/publish_on.xlsx', header = 0)
# When there are no more products to be published, it will call the function that displays the products to be published.
else:
if processes_publish_product[0].is_alive():
processes_publish_product[0].kill()
processes_publish_product.pop(0)
page_publish(1)
# Function that adds the products to the file that will store the products that will be published.
def publish_on_telegram(e):
# To check the list of products to be published
verify_list_publish = pd.read_excel('data/list_publish.xlsx', header = 0)
title_publish = verify_list_publish['title'].values
price_publish = verify_list_publish['price'].values
url_publish = verify_list_publish['url'].values
# To obtain how often the products will be published.
minutes = minutes_publish.value
# They will be used to save the data stored in list_publish.xlsx and add them to publish_on.xlsx
# (this file stores the products that will be published).
title_publish_on = []
price_publish_on = []
url_publish_on = []
minutes_publish_on = []
telegram_publish_on = []
for i in range(len(verify_list_publish)):
title_publish_on.append(title_publish[i])
price_publish_on.append(price_publish[i])
url_publish_on.append(url_publish[i])
minutes_publish_on.append(minutes)
telegram_publish_on.append('yes')
add_history = {'title': title_publish_on, 'price': price_publish_on, 'url': url_publish_on, 'min': minutes_publish_on,'telegram':telegram_publish_on}
update_publish_on = pd.DataFrame(add_history, columns = ['title', 'price', 'url', 'min', 'telegram'])
with ExcelWriter('data/publish_on.xlsx') as writer:
update_publish_on.to_excel(writer, 'Sheet', index=False)
page_publish_on(1)
# Function to change the message that will be displayed in Telegram posts.
def change_custom_message(e):
verify_custom_message = pd.read_excel('data/custom_message.xlsx', header = 0)
before_title_message = verify_custom_message['before_title'].values
original_price_message = verify_custom_message['original_price'].values
sale_price_message = verify_custom_message['sale_price'].values
currency_message = verify_custom_message['currency'].values
url_message = verify_custom_message['url'].values
label_message = e.control.label
add_custom_message = {}
if 'Before' in label_message:
before_title_message = [form_before_title_message.value]
elif 'Sale' in label_message:
sale_price_message = [form_sale_price_message.value]
elif 'Original' in label_message:
original_price_message = [form_original_price_message.value]
elif 'Currency' in label_message:
currency_message = [form_currency_message.value]
elif 'URL' in label_message:
url_message = [form_url_message.value]
else:
pass
add_custom_message['before_title'] = before_title_message
add_custom_message['original_price'] = original_price_message
add_custom_message['sale_price'] = sale_price_message
add_custom_message['currency'] = currency_message
add_custom_message['url'] = url_message
update_custom_message = pd.DataFrame(add_custom_message, columns = ['before_title', 'original_price', 'sale_price', 'currency', 'url'])
with ExcelWriter('data/custom_message.xlsx') as writer:
update_custom_message.to_excel(writer, 'Sheet', index=False)
# Function that will show the screen where the message of the products published in Telegram can be modified.
def custom_message(e):
verify_custom_message = pd.read_excel('data/custom_message.xlsx', header = 0)
before_title_message = verify_custom_message['before_title'].values
original_price_message = verify_custom_message['original_price'].values
sale_price_message = verify_custom_message['sale_price'].values
currency_message = verify_custom_message['currency'].values
url_message = verify_custom_message['url'].values
if len(verify_custom_message) != 0:
form_before_title_message.value = before_title_message[0]
form_sale_price_message.value = sale_price_message[0]
form_original_price_message.value = original_price_message[0]
form_currency_message.value = currency_message[0]
form_url_message.value = url_message[0]
title_custom_message = Text(
value="Modify the publication message",
size=20,
color="white",
weight="bold",
italic=True,
)
page.clean()
page.add(
ft.Container(height = 50, content= title_custom_message, alignment=ft.alignment.center),
ft.Divider(height=1, color="black"),
ft.Container(height= 449, content=ft.Column(controls=[
form_before_title_message,
form_sale_price_message,
form_original_price_message,
form_currency_message,
form_url_message
],
alignment="center")),
ft.Container(content= ft.Row(controls=list_all_button_menu,
alignment="center", vertical_alignment = "end"),
height = 100
)
)
# Function to delete product in the list of products to be published.
def delete_product_button(e):
id_number = e.control.data
verify_list_publish = pd.read_excel('data/list_publish.xlsx', header = 0)
title_publish = verify_list_publish['title'].values
price_publish = verify_list_publish['price'].values
currency_publish = verify_list_publish['currency'].values
url_publish = verify_list_publish['url'].values
new_title_publish = []
new_price_publish = []
new_currency_publish = []
new_url_publish = []
for i in range(len(verify_list_publish)):
if i == id_number:
pass
else:
new_title_publish.append(title_publish[i])
new_price_publish.append(price_publish[i])
new_currency_publish.append(currency_publish[i])
new_url_publish.append(url_publish[i])
list_publish_data = {}
list_publish_data['title'] = new_title_publish
list_publish_data['price'] = new_price_publish
list_publish_data['currency'] = new_currency_publish
list_publish_data['url'] = new_url_publish
list_publish_data = pd.DataFrame(list_publish_data, columns = ['title', 'price', 'currency', 'url'])
with ExcelWriter('data/list_publish.xlsx') as writer:
list_publish_data.to_excel(writer, 'Sheet', index=False)
page_publish(0)
# Function to change Amazon ID
def change_amazon_id(e):
new_amazon_id = e.control.value
verify_setting = pd.read_excel('data/setting.xlsx', header = 0)
amazon_id = verify_setting['amazon_id'].values
telegram_token = verify_setting['telegram_token'].values
chat_id = verify_setting['chat_id'].values
if len(verify_setting) > 0:
amazon_id = new_amazon_id
if pd.isnull(telegram_token[0]):
telegram_token = ''
else:
telegram_token = telegram_token[0]
if pd.isnull(chat_id[0]):
chat_id = ''
else:
chat_id = chat_id[0]
else:
amazon_id = new_amazon_id
telegram_token = ''
chat_id = ''
setting_data = {}
setting_data['amazon_id'] = [amazon_id]
setting_data['telegram_token'] = [telegram_token]
setting_data['chat_id'] = [chat_id]
setting_data = pd.DataFrame(setting_data, columns = ['amazon_id', 'telegram_token', 'chat_id'])
with ExcelWriter('data/setting.xlsx') as writer:
setting_data.to_excel(writer, 'Sheet', index=False)
# Function to change telegram token
def change_telegram_token(e):
new_telegram_token = e.control.value
verify_setting = pd.read_excel('data/setting.xlsx', header = 0)
amazon_id = verify_setting['amazon_id'].values
telegram_token = verify_setting['telegram_token'].values
chat_id = verify_setting['chat_id'].values
if len(verify_setting) > 0:
telegram_token = new_telegram_token
if pd.isnull(amazon_id[0]):
amazon_id = ''
else:
amazon_id = amazon_id[0]
if pd.isnull(chat_id[0]):
chat_id = ''
else:
chat_id = chat_id[0]
else:
amazon_id = ''
telegram_token = new_telegram_token
chat_id = ''
setting_data = {}
setting_data['amazon_id'] = [amazon_id]
setting_data['telegram_token'] = [telegram_token]
setting_data['chat_id'] = [chat_id]
setting_data = pd.DataFrame(setting_data, columns = ['amazon_id', 'telegram_token', 'chat_id'])
with ExcelWriter('data/setting.xlsx') as writer:
setting_data.to_excel(writer, 'Sheet', index=False)
# Function to change chat ID
def change_chat_id(e):
new_chat_id = e.control.value
verify_setting = pd.read_excel('data/setting.xlsx', header = 0)
amazon_id = verify_setting['amazon_id'].values
telegram_token = verify_setting['telegram_token'].values
chat_id = verify_setting['chat_id'].values
if len(verify_setting) > 0:
chat_id = new_chat_id
if pd.isnull(amazon_id[0]):
amazon_id = ''
else:
amazon_id = amazon_id[0]
if pd.isnull(telegram_token[0]):
telegram_token = ''
else:
telegram_token = telegram_token[0]
else:
amazon_id = ''
telegram_token = ''
chat_id = new_chat_id
setting_data = {}
setting_data['amazon_id'] = [amazon_id]
setting_data['telegram_token'] = [telegram_token]
setting_data['chat_id'] = [chat_id]
setting_data = pd.DataFrame(setting_data, columns = ['amazon_id', 'telegram_token', 'chat_id'])
with ExcelWriter('data/setting.xlsx') as writer:
setting_data.to_excel(writer, 'Sheet', index=False)
# Function to change the title of the products that appear in the list of products to be published.
def change_title_publish(e):
new_title = e.control.value # Stores the text of the form that is being modified.
id_number = e.control.label # Stores the label number of the text field being modified so that it can be identified.
verify_list_publish = pd.read_excel('data/list_publish.xlsx', header = 0)
title_publish = verify_list_publish['title'].values
price_publish = verify_list_publish['price'].values
currency_publish = verify_list_publish['currency'].values
url_publish = verify_list_publish['url'].values
title_publish[id_number] = new_title
list_publish_data = {}
list_publish_data['title'] = title_publish
list_publish_data['price'] = price_publish
list_publish_data['currency'] = currency_publish
list_publish_data['url'] = url_publish
list_publish_data = pd.DataFrame(list_publish_data, columns = ['title', 'price', 'currency', 'url'])
try:
with ExcelWriter('data/list_publish.xlsx') as writer:
list_publish_data.to_excel(writer, 'Sheet', index=False)
except:
sleep(1)
with ExcelWriter('data/list_publish.xlsx') as writer:
list_publish_data.to_excel(writer, 'Sheet', index=False)
# Function to change the price of the products that appear in the list of products to be published.
def change_price_publish(e):
new_price = e.control.value # Stores the text of the form that is being modified.
id_number = e.control.label # Stores the label number of the text field being modified so that it can be identified.
verify_list_publish = pd.read_excel('data/list_publish.xlsx', header = 0)
title_publish = verify_list_publish['title'].values
price_publish = verify_list_publish['price'].values
currency_publish = verify_list_publish['currency'].values
url_publish = verify_list_publish['url'].values
price_publish[id_number] = new_price
list_publish_data = {}
list_publish_data['title'] = title_publish
list_publish_data['price'] = price_publish
list_publish_data['currency'] = currency_publish
list_publish_data['url'] = url_publish
list_publish_data = pd.DataFrame(list_publish_data, columns = ['title', 'price', 'currency', 'url'])
try:
with ExcelWriter('data/list_publish.xlsx') as writer:
list_publish_data.to_excel(writer, 'Sheet', index=False)
except:
sleep(1)
with ExcelWriter('data/list_publish.xlsx') as writer:
list_publish_data.to_excel(writer, 'Sheet', index=False)
# Function to change the title of the products that appear in the list of found products.
def change_title_result(e):
new_title = e.control.value # Stores the text of the form that is being modified.
id_number = e.control.label # Stores the label number of the text field being modified so that it can be identified.
verify_search_result = pd.read_excel('data/search_result.xlsx', header = 0)
title_result = verify_search_result['title'].values
price_result = verify_search_result['price'].values
currency_result = verify_search_result['currency'].values
check_result = verify_search_result['check'].values
url_result = verify_search_result['url'].values
title_result[id_number] = new_title
search_result_data = {}
search_result_data['title'] = title_result
search_result_data['price'] = price_result
search_result_data['currency'] = currency_result
search_result_data['check'] = check_result
search_result_data['url'] = url_result
search_result_data = pd.DataFrame(search_result_data, columns = ['title', 'price', 'currency', 'check', 'url'])
try:
with ExcelWriter('data/search_result.xlsx') as writer:
search_result_data.to_excel(writer, 'Sheet', index=False)
except:
sleep(1)
with ExcelWriter('data/search_result.xlsx') as writer:
search_result_data.to_excel(writer, 'Sheet', index=False)
# Function to change the price of the products that appear in the list of found products.
def change_price_result(e):
new_price = e.control.value # Stores the text of the form that is being modified.
id_number = e.control.label # Stores the label number of the text field being modified so that it can be identified.
verify_search_result = pd.read_excel('data/search_result.xlsx', header = 0)
title_result = verify_search_result['title'].values
price_result = verify_search_result['price'].values
currency_result = verify_search_result['currency'].values
check_result = verify_search_result['check'].values
url_result = verify_search_result['url'].values
price_result[id_number] = new_price
search_result_data = {}
search_result_data['title'] = title_result
search_result_data['price'] = price_result
search_result_data['currency'] = currency_result
search_result_data['check'] = check_result
search_result_data['url'] = url_result
search_result_data = pd.DataFrame(search_result_data, columns = ['title', 'price', 'currency', 'check', 'url'])
try:
with ExcelWriter('data/search_result.xlsx') as writer:
search_result_data.to_excel(writer, 'Sheet', index=False)
except:
sleep(1)
with ExcelWriter('data/search_result.xlsx') as writer:
search_result_data.to_excel(writer, 'Sheet', index=False)
# Function that enables and disables application development support
def support_development(e):
verify_status_support = pd.read_excel('data/support_dev.xlsx', header = 0)
status = e.control.value
support_data = {}
if status:
switch_supp_dev.label = 'Supporting Development On 😊'
support_data['sup_tag'] = ['amla02-20']
support_data['sup_dev'] = ['yes']
else:
switch_supp_dev.label = 'Supporting Development Off 😢'
support_data['sup_tag'] = ['amla02-20']
support_data['sup_dev'] = ['no']
update_status_support = pd.DataFrame(support_data, columns = ['sup_tag', 'sup_dev'])
with ExcelWriter('data/support_dev.xlsx') as writer:
update_status_support.to_excel(writer, 'Sheet', index=False)
page.update()
# Function that will add the products to the list of products to be published.
def add_to_publish(self):
# The data stored in the searched products is checked.
verify_search_result = pd.read_excel('data/search_result.xlsx', header = 0)
# To be stored in the following variables:
title_result = verify_search_result['title'].values
price_result = verify_search_result['price'].values
currency_result = verify_search_result['currency'].values
check_result = verify_search_result['check'].values
url_result = verify_search_result['url'].values
# The data stored in the list of products to be published are checked.
verify_list_publish = pd.read_excel('data/list_publish.xlsx', header = 0)
# It will be stored in the following variables:
title_publish = verify_list_publish['title'].values
price_publish = verify_list_publish['price'].values
currency_publish = verify_list_publish['currency'].values
url_publish = verify_list_publish['url'].values
count = 0 # Counter to be used to identify each item stored in the lists obtained from the Excel files.
# The new variables will store the existing data in the list of products to be published and products found,
# and will also store the new data to be added.
new_title_result = []
new_price_result = []
new_currency_result = []
new_check_result = []
new_url_result = []
new_title_publish = []
new_price_publish = []
new_currency_publish = []
new_url_publish = []
# It is verified that the file with the data of the products to be published has information.
if len(verify_list_publish) > 0:
# By means of a loop, the current information of the products to be published is stored in the new variables.
for i in range(len(verify_list_publish)):
new_title_publish.append(title_publish[i])
new_price_publish.append(price_publish[i])
new_currency_publish.append(currency_publish[i])
new_url_publish.append(url_publish[i])
# It is verified that the file with the data of the products to be published has information.
if len(verify_search_result) > 0:
# Through this loop we can check the products that have been selected to be published.
# This information is stored in search_result.xlsx
for check_status in check_result:
# Products stored in the search_result.xlsx document that contain
# the value "no" in the check field will be stored in the new found products variables.
if check_status == 'no':
new_title_result.append(title_result[count])
new_price_result.append(price_result[count])
new_currency_result.append(currency_result[count])
new_check_result.append(check_result[count])
new_url_result.append(url_result[count])
# On the other hand, if they have the value "yes", they will be stored in the variables
# that will be used to store the information in the list_publish.xlsx document.
else:
new_title_publish.append(title_result[count])
new_price_publish.append(price_result[count])
new_currency_publish.append(currency_result[count])
new_url_publish.append(url_result[count])
count+=1
list_publish_data = {}
list_publish_data['title'] = new_title_publish
list_publish_data['price'] = new_price_publish
list_publish_data['currency'] = new_currency_publish
list_publish_data['url'] = new_url_publish
list_publish_data = pd.DataFrame(list_publish_data, columns = ['title', 'price', 'currency', 'url'])
with ExcelWriter('data/list_publish.xlsx') as writer:
list_publish_data.to_excel(writer, 'Sheet', index=False)
search_result_data = {}
search_result_data['title'] = new_title_result
search_result_data['price'] = new_price_result
search_result_data['currency'] = new_currency_result
search_result_data['check'] = new_check_result
search_result_data['url'] = new_url_result
search_result_data = pd.DataFrame(search_result_data, columns = ['title', 'price', 'currency', 'check', 'url'])
with ExcelWriter('data/search_result.xlsx') as writer:
search_result_data.to_excel(writer, 'Sheet', index=False)
page_search_result(0)
else:
pass
# Function to delete the products added in the search result.
def select_all_search_result(e):
# The data stored in the searched products is checked.
verify_search_result = pd.read_excel('data/search_result.xlsx', header = 0)
# To be stored in the following variables:
title_result = verify_search_result['title'].values
price_result = verify_search_result['price'].values
currency_result = verify_search_result['currency'].values
check_result = verify_search_result['check'].values
url_result = verify_search_result['url'].values
status_select = e.control.text
# For all products to be selected, "yes" must be placed in the "check" column.
new_check_values = []
for i in range(len(verify_search_result)):
if 'Unselect' in status_select:
new_check_values.append('no')
else:
new_check_values.append('yes')
update_data = {}
update_data['title'] = title_result
update_data['price'] = price_result
update_data['currency'] = currency_result
update_data['check'] = new_check_values
update_data['url'] = url_result
search_result_data = pd.DataFrame(update_data, columns = ['title', 'price', 'currency', 'check', 'url'])
with ExcelWriter('data/search_result.xlsx') as writer:
search_result_data.to_excel(writer, 'Sheet', index=False)
sleep(1)
page_search_result(1)
# Function to delete the products added in the history.
def delete_all_history(self):
history_data = pd.DataFrame(columns = ['date', 'title', 'price', 'url', 'platform'])
with ExcelWriter('data/history.xlsx') as writer:
history_data.to_excel(writer, 'Sheet', index=False)
sleep(1)
page_history(1)
# Function to delete the products added in the search result.
def delete_all_search_result(self):
search_result_data = pd.DataFrame(columns = ['title', 'price', 'currency', 'check', 'url'])
with ExcelWriter('data/search_result.xlsx') as writer:
search_result_data.to_excel(writer, 'Sheet', index=False)
sleep(1)
page_search_result(1)
# Function to delete the products added to the list of products to be published.
def delete_all_products_publish(self):
list_publish_data = pd.DataFrame(columns = ['title', 'price', 'currency', 'url'])
with ExcelWriter('data/list_publish.xlsx') as writer:
list_publish_data.to_excel(writer, 'Sheet', index=False)
sleep(1)
page_publish(1)
# Function to select the products shown in the search result that will be added to the list of products to be published.
def check_button(e):
e.control.selected = not e.control.selected
e.control.update()
verify_search_result = pd.read_excel('data/search_result.xlsx', header = 0)
title_result = verify_search_result['title'].values
price_result = verify_search_result['price'].values
currency_result = verify_search_result['currency'].values
check_result = verify_search_result['check'].values
url_result = verify_search_result['url'].values
if e.control.selected == False:
pass
else:
check_result[e.control.data] = 'yes'
if e.control.selected == True:
pass
else:
check_result[e.control.data] = 'no'
search_result_data = {}
search_result_data['title'] = title_result
search_result_data['price'] = price_result
search_result_data['currency'] = currency_result
search_result_data['check'] = check_result
search_result_data['url'] = url_result
search_result_data = pd.DataFrame(search_result_data, columns = ['title', 'price', 'currency', 'check', 'url'])
try:
with ExcelWriter('data/search_result.xlsx') as writer:
search_result_data.to_excel(writer, 'Sheet', index=False)
except:
sleep(1)
with ExcelWriter('data/search_result.xlsx') as writer:
search_result_data.to_excel(writer, 'Sheet', index=False)
# Function to open the URL of the products added in the list of products to be published.
def view_url_list_publish(e):
try:
verify_list_publish = pd.read_excel('data/list_publish.xlsx', header = 0)
title_publish = verify_list_publish['title'].values
url_publish = verify_list_publish['url'].values
except:
sleep(1)
verify_list_publish = pd.read_excel('data/list_publish.xlsx', header = 0)
title_publish = verify_list_publish['title'].values
url_publish = verify_list_publish['url'].values
webbrowser.open(url_publish[e.control.data])
# Function to open the URL of the products added in the history of published products.
def view_url_history(e):
try:
verify_history = pd.read_excel('data/history.xlsx', header = 0)
url_history = verify_history['url'].values
except:
sleep(1)
verify_history = pd.read_excel('data/history.xlsx', header = 0)
url_history = verify_history['url'].values
webbrowser.open(url_history[e.control.data])
# Function to open the URL of the products added in the search result.
def view_url_search_result(e):
try:
verify_search_result = pd.read_excel('data/search_result.xlsx', header = 0)
title_result = verify_search_result['title'].values