-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFontUseWizard Updated.py
2400 lines (2076 loc) · 108 KB
/
FontUseWizard Updated.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
#Last update: 07/10/20
import os
import shutil
import csv
import pyxj
import re
import struct
from pyxj import dialog
from pathlib import Path
from fontio3 import fontedit
from fontio3.CFF import CFF
from fontio3.utilities.filewalker import FileWalker
import plistlib
from urllib.request import urlopen
import unicodedata
from libfont3 import fontEditorFromFont
import mmap
from docx import Document
from docx.shared import Inches
from collections import defaultdict
from datetime import date
from zipfile import ZipFile
from enum import Enum
import string
class Usecase(Enum):
App_Android = 1
App_IOS = 2
Website = 3
DigitalAds = 4
PDF = 5
SCRIPT_VERSION="v1.03"
def fix_nulls(s):
for line in s:
yield line.replace('\0', '')
def remove_control_characters(s):
return "".join(ch for ch in s if unicodedata.category(ch)[0]!="C")
def initFontData():
default_value = ''
font_dict = dict.fromkeys(['Name','Remarks','Copyright','Trademark','Family','Subfamily','LicenseDesc','LicenseURL','UniqueID','Misc1','Misc2','Version','Manufacturer','Designer',
'DesignerURL','Vendor','VendorURL','VendorID','FontFileName','FileType','Path','WebPath','Foundry','Enforce','WhyEnforce','UseCase','Title','AppPlatform','AppDev','AppURL','VerifiedDomain','LicenseIndicator'],default_value)
return font_dict
def makeFontFromCSV(row):
font = initFontData()
font['Enforce'] = row[0]
font['Name'] = row[1]
font['UseCase'] = row[2]
font['Title'] = row[3]
font['FontFileName'] = row[4]
font['Copyright'] = row[5]
font['Trademark'] = row[6]
font['Family'] = row[7]
font['Subfamily'] = row[8]
font['LicenseDesc'] = row[9]
font['LicenseURL'] = row[10]
font['UniqueID'] = row[11]
font['Misc1'] = row[12]
font['Misc2'] = row[13]
font['Version'] = row[14]
font['Manufacturer'] = row[15]
font['Designer'] = row[16]
font['DesignerURL'] = row[17]
font['Vendor'] = row[18]
font['VendorURL'] = row[19]
font['VendorID'] = row[20]
font['FileType'] = row[21]
font['Foundry'] = row[22]
font['Path'] = row[23]
font['WebPath'] = row[24]
font['VerifiedDomain'] = row[25]
font['LicenseIndicator'] = row[26]
font['AppPlatform'] = row[27]
font['AppDev'] = row[28]
font['AppURL'] = row[29]
font['WhyEnforce'] = row[30]
font['Remarks'] = row[31]
return font
#write results from general scan to a CSV file
def write_dir_scan(fonts_list, path):
outpath = path + 'FontInfo_' + SCRIPT_VERSION + '.csv'
output = csv.writer(open(outpath,'w',encoding='utf8', newline = ''))
#Write CSV headers
output.writerow(['Enforceable IP?','Font Name','Font File Name','Copyright','Trademark','Family', 'Subfamily','License Description', 'License Info URL', 'Unique ID', 'Misc1','Misc2','Version', 'Manufacturer', 'Designer', 'Designer URL','Vendor', 'Vendor URL', 'Vendor ID','File Type','Path','WhyEnforce','Remarks'])
for font in fonts_list:
remarks = ''
if 'Remarks' in font.keys():
for remark in font['Remarks']:
remarks = remarks + remark + ' '
if font['VendorID'] != '':
font['VendorID'] = font['VendorID'].decode('utf-8')
output.writerow([font['Enforce'], font['Name'], font['FontFileName'], font['Copyright'], font['Trademark'], font['Family'], font['Subfamily'], font['LicenseDesc'], font['LicenseURL'], font['UniqueID'], font['Misc1'],font['Misc2'], font['Version'], font['Manufacturer'], font['Designer'], font['DesignerURL'], font['Vendor'], font['VendorURL'], font['VendorID'], font['FileType'],font['Path'], font['WhyEnforce'], remarks])
print('Done! Results saved to ' + outpath)
#similar to write_dir_scan but includes extra information pertaining to use case
def create_font_use_csv(fonts_list, path):
output = csv.writer(open(path,'w',encoding='utf8', newline = ''))
#Write CSV headers
output.writerow(['Enforceable IP?','Font Name','Use Case', 'Website/App Title', 'Font File Name','Copyright','Trademark','Family', 'Subfamily','License Description', 'License Info URL', 'Unique ID', 'Misc1','Misc2','Version', 'Manufacturer', 'Designer', 'Designer URL','Vendor', 'Vendor URL', 'Vendor ID','File Type','Foundry (test)','Path','Web Path','Verified Domain', 'License Indicator','App Platform', 'App Developer', 'App URL','WhyEnforce','Remarks'])
waybackURLs = ['https://web.archive.org/web/20200406145022/',
'https://web.archive.org/web/20200101072516/',
'https://web.archive.org/web/20190702000358/',
'https://web.archive.org/web/20190101081056/',
'https://web.archive.org/web/20180701184757/',
'https://web.archive.org/web/20180104141938/',
'https://web.archive.org/web/20170701023847/',
'https://web.archive.org/web/20170101023847/',
'https://web.archive.org/web/20160711135651/',
'https://web.archive.org/web/20160112094559/',
'https://web.archive.org/web/20150706032903/',
'https://web.archive.org/web/20150101071917/',
'https://web.archive.org/web/20140711180223/',
'https://web.archive.org/web/20140103013856/',
'https://web.archive.org/web/20130708001814/',
'https://web.archive.org/web/20130101103045/',
'https://web.archive.org/web/20120602145257/',
'https://web.archive.org/web/20120104183204/',
'https://web.archive.org/web/20110608173044/',
'https://web.archive.org/web/20110101110846/',
'https://web.archive.org/web/20100102003419/']
waybackSet = set()
for font in fonts_list:
remarks = ''
if 'Remarks' in font.keys():
for remark in font['Remarks']:
remarks = remarks + remark + ' '
for key in ['Enforce', 'Name','UseCase','Title','FontFileName','Copyright','Trademark','Family','Subfamily','LicenseDesc','LicenseURL','UniqueID','Misc1','Misc2','Version','Manufacturer','Designer','DesignerURL','Vendor','VendorURL','VendorID', 'FileType','Foundry','Path','WebPath','VerifiedDomain','LicenseIndicator','AppPlatform','AppDev','AppURL', 'WhyEnforce']:
if key not in font:
font[key] = ""
if font['VendorID'] != '':
font['VendorID'] = font['VendorID'].decode('utf-8')
if font['UseCase'] == 'Web Font' and font['Enforce'] != 'No':
#for url in waybackURLs:
#waybackCSV.writerow([url+font['Title']])
url = remove_prefix(font['Title'], "https")
url = remove_prefix(url, "www.")
waybackSet.add("https://www." + url)
if font['UseCase'] == 'PDF':
font['Title'] = os.path.basename(os.path.dirname(font['Path'])) + '.pdf'
output.writerow([font['Enforce'], font['Name'], font['UseCase'], font['Title'], font['FontFileName'], font['Copyright'], font['Trademark'], font['Family'], font['Subfamily'], font['LicenseDesc'], font['LicenseURL'], font['UniqueID'], font['Misc1'],font['Misc2'], font['Version'], font['Manufacturer'], font['Designer'], font['DesignerURL'], font['Vendor'], font['VendorURL'], font['VendorID'], font['FileType'],font['Foundry'],font['Path'],font['WebPath'], font['VerifiedDomain'],font['LicenseIndicator'],font['AppPlatform'],font['AppDev'],font['AppURL'],font['WhyEnforce'],remarks])
if len(waybackSet)>0:
waybackCSVFile = os.path.join(os.path.dirname(path), 'wayback.csv')
waybackCSV = csv.writer(open(waybackCSVFile, 'w', encoding='utf8', newline=''))
for url in waybackSet:
for wayback in waybackURLs:
waybackCSV.writerow([wayback + url])
def remove_prefix(str, prefix):
if str.startswith(prefix):
return str[len(prefix):]
else:
return str
def create_font_use_doc(csv_path, dirpath, pre_csv_path = '', redirectedURLs = None):
#prompt for client name
client = pyxj.askString('Please enter the name of the client. ' + SCRIPT_VERSION, 'Client: ', cancelable=False)
with open(csv_path,'r', encoding="utf8") as myFile:
reader = csv.reader(fix_nulls(myFile))
rows = list(reader)
document = Document()
#set up document font
docFont = document.styles['Normal'].font
docFont.name = 'Helvetica Now Display Light'
heading1Font = document.styles['Heading 1'].font
heading1Font.name = 'Helvetica Now Display Light'
heading2Font = document.styles['Heading 2'].font
heading2Font.name = 'Helvetica Now Display Light'
heading3Font = document.styles['Heading 3'].font
heading3Font.name = 'Helvetica Now Display Light'
section = document.sections[0]
header = section.header
paragraph = header.paragraphs[0]
paragraph.text = 'Monotype Imaging\t\t' + date.today().isoformat()
paragraph.style = document.styles["Header"]
iOS_apps = []
android_apps = []
websites = []
metadata_fonts = []
fonts_list = []
oldestURLs = {}
document.add_paragraph('[REPLACE WITH TABLE OF CONTENTS]')
for row in rows[1:]:
fontData = makeFontFromCSV(row)
if fontData['Enforce'] != 'No':
fonts_list.append(fontData)
#oldest URL Logic
if pre_csv_path != '':
waybackRegex = 'web.archive.org\/web\/\d{14}\/'
fonts_list = sorted(fonts_list, key=lambda s: re.sub(waybackRegex, "", s['Title']))
temp_font_list = []
prevURL = ''
for font in fonts_list:
actualURL = re.sub(waybackRegex, "", font['Title'])
if prevURL != actualURL or font == fonts_list[-1]:
if len(temp_font_list) > 0:
currURL = temp_font_list[len(temp_font_list) -1]['Title']
temp_fontnames = []
old_dict = {}
temp_font_list.reverse()
for tempfont in temp_font_list:
if currURL == tempfont['Title']:
temp_fontnames.append(tempfont['Name'])
else:
break
temp_font_list.reverse()
for temp_fontname in temp_fontnames:
for tempfont in temp_font_list:
if tempfont['Name'] == temp_fontname:
if redirectedURLs and tempfont['Title'] in redirectedURLs:
old_dict[temp_fontname] = redirectedURLs[tempfont['Title']]
else:
old_dict[temp_fontname] = tempfont['Title']
break
if prevURL not in oldestURLs:
oldestURLs[prevURL] = {}
oldestURLs[prevURL]['CurrentFonts'] = old_dict
temp_font_list.clear()
prevURL = actualURL
temp_font_list.append(font)
if actualURL not in oldestURLs:
oldestURLs[actualURL] = {}
if redirectedURLs and font['Title'] in redirectedURLs:
oldestURLs[actualURL]['OldestURL'] = redirectedURLs[font['Title']]
else:
oldestURLs[actualURL]['OldestURL'] = font['Title']
fonts_list = []
with open(pre_csv_path, 'r', encoding="utf8") as myFile:
reader = csv.reader(fix_nulls(myFile))
rows = list(reader)
for row in rows[1:]:
fontData = makeFontFromCSV(row)
if fontData['Enforce'] != 'No':
fonts_list.append(fontData)
iOS_apps = getIOSApps(fonts_list)
android_apps, amazon_apps = getAndroidApps(fonts_list)
websites = getWebsites(fonts_list, 'Web Font')
ads = getWebsites(fonts_list, 'Digital Ad')
pdfs = getWebsites(fonts_list, 'PDF')
if len(fonts_list) > 0:
#Write Docs
if len(iOS_apps) > 0:
document.add_heading(client + ' Mobile Applications [iOS]', level=1)
for app in iOS_apps:
document.add_heading(app[0], level=2)
p = document.add_paragraph('Developer: ', style = 'List Bullet')
p.add_run(app[1])
p = document.add_paragraph('Web URL: ', style = 'List Bullet')
p.add_run(app[2])
document.add_paragraph("Embedded Font Software", style = 'List Bullet')
for font in app[3]:
if 'AR/VR' in font['UseCase']:
document.add_paragraph('AR/VR Font - ' + font['Name'], style='List Bullet 2')
else:
document.add_paragraph(font['Name'], style = 'List Bullet 2')
document.add_paragraph('Screenshot of Font Software Embedded Within Mobile Application', style = 'List Bullet')
for path in set(app[4]):
document.add_paragraph(path)
document.add_paragraph('App Version History', style = 'List Bullet')
app_annie_url = 'https://www.appannie.com/apps/ios/app/' + app[2].split('/')[-1].replace('id','') + '/details/'
document.add_paragraph(app_annie_url)
document.add_paragraph('Internal Notes', style = 'List Bullet')
#check levels of enforcement
enf_MT = False
enf_3p = False
for font in app[3]:
if font['Enforce'] == 'Yes':
enf_MT = True
elif font['Enforce'] != 'Yes':
enf_3p = True
if enf_MT:
document.add_paragraph("Embedded Monotype Font Software", style = 'List Bullet 2')
for font in app[3]:
if font['Enforce'] == 'Yes':
document.add_paragraph(font['Name'], style = 'List Bullet 3')
if enf_3p:
document.add_paragraph("Other Embedded Font Software", style = 'List Bullet 2')
for font in app[3]:
if font['Enforce'] != 'Yes':
document.add_paragraph(font['Name'], style = 'List Bullet 3')
if len(android_apps) > 0:
document.add_heading(client + ' Mobile Applications [Android]', level=1)
write_android_apps(android_apps, document)
if len(amazon_apps) > 0:
document.add_heading(client + ' Mobile Applications [Amazon]', level=1)
write_android_apps(amazon_apps, document)
if len(websites) > 0:
write_websites(client, document, oldestURLs, dirpath, pre_csv_path, websites, Usecase.Website)
if len(ads) > 0:
write_websites(client, document, oldestURLs, dirpath, pre_csv_path, ads, Usecase.DigitalAds)
if len(pdfs) > 0:
write_websites(client, document, oldestURLs, dirpath, pre_csv_path, pdfs, Usecase.PDF)
#write metadata
document.add_heading('Font Software Metadata', level = 1)
#fonts_check: [filename, name]
fonts_check = []
fonts_check.append(['check','check'])
metadata_fonts = []
for font in fonts_list:
found = False
for checkfont in fonts_check:
if font['FontFileName'] == checkfont[0] and font['Name'] == checkfont[1]:
found = True
if not found:
fonts_check.append([font['FontFileName'],font['Name']])
metadata_fonts.append(font)
#sorting metadata so that it's lumped together by font name
sorted_metadata = sorted(metadata_fonts, key = lambda k : k['Name'])
disp_names = []
for font in sorted_metadata:
if font['Name'] not in disp_names:
document.add_heading(font['Name'], level = 2)
disp_names.append(font['Name'])
table = document.add_table(rows = 17, cols = 2)
table.style = 'TableGrid'
hdr_cells = table.columns[0].cells
for cell in hdr_cells:
cell.width = Inches(0.8)
hdr_cells[0].text = 'name id' #filename
hdr_cells[1].text = 'Full Name'
hdr_cells[2].text = 'Family'
hdr_cells[3].text = 'Subfamily'
hdr_cells[4].text = 'Copyright'
hdr_cells[5].text = 'Trademark'
hdr_cells[6].text = 'License Description'
hdr_cells[7].text = 'License Info URL'
hdr_cells[8].text = 'Unique ID'
hdr_cells[9].text = 'Version'
hdr_cells[10].text = 'Manufacturer'
hdr_cells[11].text = 'Designer'
hdr_cells[12].text = 'Designer URL'
hdr_cells[13].text = 'Vendor'
hdr_cells[14].text = 'Vendor URL'
hdr_cells[15].text = 'Vendor ID'
hdr_cells[16].text = 'Misc'
fnt_cells = table.columns[1].cells
prepare_doc_table(fnt_cells, font)
document.add_paragraph('')
document.add_heading('Internal Notes', level = 1)
document.add_paragraph('')
document.add_heading('Company Structure', level = 2)
document.add_paragraph('')
document.add_heading('Reviewed Websites', level = 2)
document.add_paragraph('')
document.add_heading('Reviewed Apps', level = 2)
document.add_paragraph('')
#document.add_heading('License Checks', level = 2)
#document.add_paragraph('')
#document.add_heading('SFDC', level = 3)
#document.add_paragraph('')
#document.add_heading('DC', level = 3)
#document.add_paragraph('')
outfileName = client + " Font Use (Internal Version).docx"
outpath = os.path.join(os.path.dirname(csv_path), outfileName)
document.save(outpath)
def prepare_doc_table(fnt_cells, font, handleException = False):
if not handleException:
try:
fnt_cells[0].text = font['FontFileName']
fnt_cells[1].text = font['Name']
fnt_cells[2].text = font['Family']
fnt_cells[3].text = font['Subfamily']
fnt_cells[4].text = font['Copyright']
fnt_cells[5].text = font['Trademark']
fnt_cells[6].text = font['LicenseDesc']
fnt_cells[7].text = font['LicenseURL']
fnt_cells[8].text = font['UniqueID']
fnt_cells[9].text = font['Version']
fnt_cells[10].text = font['Manufacturer']
fnt_cells[11].text = font['Designer']
fnt_cells[12].text = font['DesignerURL']
fnt_cells[13].text = font['Vendor']
fnt_cells[14].text = font['VendorURL']
fnt_cells[15].text = font['VendorID']
fnt_cells[16].text = font['Misc1']
except:
prepare_doc_table(fnt_cells, font, True)
else:
try:
fnt_cells[0].text = filter(lambda x: x in string.printable, font['FontFileName'])
fnt_cells[1].text = filter(lambda x: x in string.printable, font['Name'])
fnt_cells[2].text = filter(lambda x: x in string.printable, font['Family'])
fnt_cells[3].text = filter(lambda x: x in string.printable, font['Subfamily'])
fnt_cells[4].text = filter(lambda x: x in string.printable, font['Copyright'])
fnt_cells[5].text = filter(lambda x: x in string.printable, font['Trademark'])
fnt_cells[6].text = filter(lambda x: x in string.printable, font['LicenseDesc'])
fnt_cells[7].text = filter(lambda x: x in string.printable, font['LicenseURL'])
fnt_cells[8].text = filter(lambda x: x in string.printable, font['UniqueID'])
fnt_cells[9].text = filter(lambda x: x in string.printable, font['Version'])
fnt_cells[10].text = filter(lambda x: x in string.printable, font['Manufacturer'])
fnt_cells[11].text = filter(lambda x: x in string.printable, font['Designer'])
fnt_cells[12].text = filter(lambda x: x in string.printable, font['DesignerURL'])
fnt_cells[13].text = filter(lambda x: x in string.printable, font['Vendor'])
fnt_cells[14].text = filter(lambda x: x in string.printable, font['VendorURL'])
fnt_cells[15].text = filter(lambda x: x in string.printable, font['VendorID'])
fnt_cells[16].text = filter(lambda x: x in string.printable, font['Misc1'])
except:
pass
def write_android_apps(android_apps, document):
for app in android_apps:
document.add_heading(app, level=2)
p = document.add_paragraph('Developer: ', style='List Bullet')
p.add_run(android_apps[app][0])
p = document.add_paragraph('Web URL: ', style='List Bullet')
p.add_run(android_apps[app][1])
document.add_paragraph("Embedded Font Software", style='List Bullet')
for font in android_apps[app][2]:
if 'AR/VR' in font['UseCase']:
document.add_paragraph('AR/VR Font - ' + font['Name'], style='List Bullet 2')
else:
document.add_paragraph(font['Name'], style='List Bullet 2')
document.add_paragraph('Screenshot of Font Software Embedded Within Mobile Application', style='List Bullet')
for path in set(android_apps[app][3]):
document.add_paragraph(path)
document.add_paragraph('App Version History', style='List Bullet')
app_annie_url = 'https://www.appannie.com/apps/google-play/app/' + android_apps[app][2][0][
'Title'] + '/details/'
document.add_paragraph(app_annie_url)
# check levels of enforcement
document.add_paragraph('Internal Notes', style='List Bullet')
enf_MT = False
enf_3p = False
for font in android_apps[app][2]:
if font['Enforce'] == 'Yes':
enf_MT = True
elif font['Enforce'] != 'Yes':
enf_3p = True
if enf_MT:
document.add_paragraph("Embedded Monotype Font Software", style='List Bullet 2')
for font in android_apps[app][2]:
if font['Enforce'] == 'Yes':
document.add_paragraph(font['Name'], style='List Bullet 3')
if enf_3p:
document.add_paragraph("Other Embedded Font Software (UFDA, MyFonts Agreement, Other)",
style='List Bullet 2')
for font in android_apps[app][2]:
if font['Enforce'] != 'Yes':
document.add_paragraph(font['Name'], style='List Bullet 3')
def add_picture_in_document_if_exists(document, dirpath, website, font, filename):
web_research_path_arr = font['Path'].split('/') if(font['Path']) else os.path.join(dirpath, '../web_research', website).split('/')
# print(web_research_path_arr)
if(font['Path']):
web_research_path_arr.pop()
web_research_path = '/'.join(web_research_path_arr)
final_image_path = web_research_path + '/images/' + filename
print(final_image_path)
if os.path.exists(final_image_path):
document.add_picture(final_image_path, width=Inches(5.0))
def insert_website_trafic_image(document, font, dirpath, website):
add_picture_in_document_if_exists(document, dirpath, website, font, 'websiteTrafic.jpg')
def insert_fonts_list_image(document, font, dirpath, website):
add_picture_in_document_if_exists(document, dirpath, website, font, 'fontsList.jpg')
def write_websites(client, document, oldestURLs, dirpath, pre_csv_path, websites, usecase):
if usecase == Usecase.DigitalAds:
document.add_heading(client + ' HTML Ads', level=1)
elif usecase == Usecase.Website:
document.add_heading(client + ' Websites', level=1)
elif usecase == Usecase.PDF:
document.add_heading(client + ' PDFs', level=1)
for website in websites:
document.add_heading(website, level=2)
if usecase == Usecase.Website:
document.add_paragraph('Web Fonts', style='List Bullet')
else:
document.add_paragraph('Fonts', style='List Bullet')
for font in websites[website]:
if 'AR/VR' in font['UseCase']:
document.add_paragraph('AR/VR Font - ' + font['Name'], style='List Bullet 2')
else:
document.add_paragraph(font['Name'], style='List Bullet 2')
document.add_paragraph('Estimated Website Traffic', style='List Bullet')
document.add_paragraph('')
insert_website_trafic_image(document, font, dirpath, website)
document.add_paragraph('Screenshot of Web Font Software in Use on Website', style='List Bullet')
insert_fonts_list_image(document, font, dirpath, website)
displayed_domains = []
for font in websites[website]:
if font['VerifiedDomain'] not in displayed_domains:
displayed_domains.append(font['VerifiedDomain'])
document.add_paragraph(font['VerifiedDomain'])
if usecase == Usecase.Website:
document.add_paragraph('Screenshot of [] Web Font Software in Use on Website to Edit Text', style='List Bullet')
document.add_paragraph('')
document.add_paragraph('Screenshot of Web Font Software in Use on Website Dating Back to []',
style='List Bullet')
if pre_csv_path != '' and website in oldestURLs:
document.add_paragraph(oldestURLs[website]['OldestURL'])
document.add_paragraph("Current font usage Dating Back to []", style='List Bullet 2')
for font in oldestURLs[website]['CurrentFonts']:
document.add_paragraph(font + " - " + oldestURLs[website]['CurrentFonts'][font] , style='List Bullet 3')
document.add_paragraph('')
document.add_paragraph('Internal Notes & License Indicators', style='List Bullet')
# check levels of enforcement
enf_MT = False
enf_3p = False
for font in websites[website]:
if font['Enforce'] == 'Yes':
enf_MT = True
elif font['Enforce'] != 'Yes':
enf_3p = True
if enf_MT:
document.add_paragraph("Monotype Web Font Software", style='List Bullet 2')
for font in websites[website]:
if font['Enforce'] == 'Yes':
document.add_paragraph(font['Name'], style='List Bullet 3')
if enf_3p:
document.add_paragraph("Other Web Font Software (UFDA, MyFonts Agreement, Other)", style='List Bullet 2')
for font in websites[website]:
if font['Enforce'] != 'Yes':
document.add_paragraph(font['Name'], style='List Bullet 3')
li_present = False
for font in websites[website]:
if font['LicenseIndicator'] != '' or 'com.myfonts' in font['UniqueID']:
li_present = True
if li_present:
document.add_paragraph('License Indicators', style='List Bullet 2')
license_indicators = []
for font in websites[website]:
if font['LicenseIndicator'] != '' and font['LicenseIndicator'] not in license_indicators:
document.add_paragraph(font['LicenseIndicator'], style='List Bullet 3')
if 'projectid' in font['LicenseIndicator']:
document.add_paragraph(
'Type: Monotype WFS. Project ID can be searched in MT Admin to find license details')
elif 'fontids' in font['LicenseIndicator']:
document.add_paragraph(
'Type: Linotype.com WF Purchase. Reach out to Monotype CS ([email protected]) for help checking for license details')
license_indicators.append(font['LicenseIndicator'])
if 'com.myfonts' in font['UniqueID']:
li = 'MFWF. ID: ' + font['UniqueID'].rpartition('.')[-1]
if li not in license_indicators:
document.add_paragraph(li, style='List Bullet 3')
document.add_paragraph(
'A Pre Sales PSD can be submitted for the 4 digit ID in order to obtain the MyFonts license which generated this web font.')
license_indicators.append(li)
#def create_ap_web(csv_path, dirpath, *nonuse_sites):
def create_ap_web(csv_path, dirpath):
fonts_list = []
with open(csv_path,'r', encoding="utf8") as myFile:
reader = csv.reader(fix_nulls(myFile))
rows = list(reader)
for row in rows[1:]:
fontData = makeFontFromCSV(row)
fonts_list.append(fontData)
outpath = dirpath + ' Websites (EXT3).csv'
output = csv.writer(open(outpath,'w',encoding='utf8', newline = ''))
#write csv headers
output.writerow(['Brand/Subsidiary','Domain','Font Name', 'Enforceable IP?','Editable Text?' 'License?', 'Page Views', 'Font Comments', 'Website Comments'])
for font in fonts_list:
if font['UseCase'] == 'Web Font' or font['UseCase'] == 'Digital Ad':
output.writerow(['',font['Title'], font['Name'], font['Enforce'],'', '', '', font['Remarks'], ''])
#if nonuse_sites:
# for site in nonuse_site:
# output.writerow(['',site,'system fonts', 'No', 'No', 'NA','','',''])
def create_ap_apps(csv_path, dirpath):
fonts_list = []
with open(csv_path,'r', encoding="utf8") as myFile:
reader = csv.reader(fix_nulls(myFile))
rows = list(reader)
for row in rows[1:]:
fontData = makeFontFromCSV(row)
fonts_list.append(fontData)
outpath = dirpath + ' Apps (EXT2).csv'
output = csv.writer(open(outpath,'w',encoding='utf8', newline = ''))
#write csv headers
output.writerow(['App Name','Platform','App Status','Font Name', 'Enforceable IP?', 'License?', 'App Initial Release Date', 'App Current Version Date', 'Font Comments', 'Website Comments'])
for font in fonts_list:
if 'Mobile App' in font['UseCase']:
output.writerow([font['Title'], font['AppPlatform'], 'Active', font['Name'], font['Enforce'], '', '', '', font['Remarks'], ''])
def find_iOS_apps(dev_url,my_country,outpath):
found_apps = []
apps = []
cc_list_iOS = [['ae','United Arab Emirates'],['ag','Antigua and Barbuda'],['ai','Anguilla'],['al','Albania'],['am','Armenia'],['ao','Angola'],['ar','Argentina'],['at','Austria'],['au','Australia'],['az','Azerbaijan'],['bb','Barbados'],['be','Belgium'],['bf','Burkina-Faso'],['bg','Bulgaria'],['bh','Bahrain'],['bj','Benin'],['bm','Bermuda'],['bn','Brunei Darussalam'],['bo','Bolivia'],['br','Brazil'],['bs','Bahamas'],['bt','Bhutan'],['bw','Botswana'],['by','Belarus'],['bz','Belize'],['ca','Canada'],['cg','Democratic Republic of the Congo'],['ch','Switzerland'],['cl','Chile'],['cn','China'],['co','Colombia'],['cr','Costa Rica'],['cv','Cape Verde'],['cy','Cyprus'],['cz','Czech Republic'],['de','Germany'],['dk','Denmark'],['dm','Dominica'],['do','Dominican Republic'],['dz','Algeria'],['ec','Ecuador'],['ee','Estonia'],['eg','Egypt'],['es','Spain'],['fi','Finland'],['fj','Fiji'],['fm','Federated States of Micronesia'],['fr','France'],['gb','Great Britain'],['gd','Grenada'],['gh','Ghana'],['gm','Gambia'],['gr','Greece'],['gt','Guatemala'],['gw','Guinea Bissau'],['gy','Guyana'],['hk','Hong Kong'],['hn','Honduras'],['hr','Croatia'],['hu','Hungaria'],['id','Indonesia'],['ie','Ireland'],['il','Israel'],['in','India'],['is','Iceland'],['it','Italy'],['jm','Jamaica'],['jo','Jordan'],['jp','Japan'],['ke','Kenya'],['kg','Krygyzstan'],['kh','Cambodia'],['kn','Saint Kitts and Nevis'],['kr','South Korea'],['kw','Kuwait'],['ky','Cayman Islands'],['kz','Kazakhstan'],['la','Laos'],['lb','Lebanon'],['lc','Saint Lucia'],['lk','Sri Lanka'],['lr','Liberia'],['lt','Lithuania'],['lu','Luxembourg'],['lv','Latvia'],['md','Moldova'],['mg','Madagascar'],['mk','Macedonia'],['ml','Mali'],['mn','Mongolia'],['mo','Macau'],['mr','Mauritania'],['ms','Montserrat'],['mt','Malta'],['mu','Mauritius'],['mw','Malawi'],['mx','Mexico'],['my','Malaysia'],['mz','Mozambique'],['na','Namibia'],['ne','Niger'],['ng','Nigeria'],['ni','Nicaragua'],['nl','Netherlands'],['no','Norway'],['np','Nepal'],['nz','New Zealand'],['om','Oman'],['pa','Panama'],['pe','Peru'],['pg','Papua New Guinea'],['ph','Philippines'],['pk','Pakistan'],['pl','Poland'],['pt','Portugal'],['pw','Palau'],['py','Paraguay'],['qa','Qatar'],['ro','Romania'],['ru','Russia'],['sa','Saudi Arabia'],['sb','Soloman Islands'],['sc','Seychelles'],['se','Sweden'],['sg','Singapore'],['si','Slovenia'],['sk','Slovakia'],['sl','Sierra Leone'],['sn','Senegal'],['sr','Suriname'],['st','Sao Tome e Principe'],['sv','El Salvador'],['sz','Swaziland'],['tc','Turks and Caicos Islands'],['td','Chad'],['th','Thailand'],['tj','Tajikistan'],['tm','Turkmenistan'],['tn','Tunisia'],['tr','Turkey'],['tt','Republic of Trinidad and Tobago'],['tw','Taiwan'],['tz','Tanzania'],['ua','Ukraine'],['ug','Uganda'],['us','United States'],['uy','Uruguay'],['uz','Uzbekistan'],['vc','Saint Vincent and the Grenadines'],['ve','Venezuela'],['vg','British Virgin Islands'],['vn','Vietnam'],['ye','Yemen'],['za','South Africa'],['zw','Zimbabwe']]
for cc in cc_list_iOS:
url = urlopen(dev_url.replace("/developer/","/" + str(cc[0]) + "/developer/"))
soup = BeautifulSoup(url.read())
for app in soup.find_all('a', {'class' : re.compile('we-lockup *')}):
app_url = app['href']
for foo in app.find_all('div', class_='we-lockup__title'):
app_name = remove_control_characters(foo.text.strip())
app_id = app_url.split('/')[-1]
if app_id not in found_apps:
apps.append(["iOS",app_name,app_url,app_id,[cc[1]]])
found_apps.append(app_id)
#already found this app, add country to the list of stores
else:
for ipa in apps:
if ipa[3] == app_id:
ipa[4].append(cc[1])
outpath = outpath + 'iOS_countries.csv'
output = csv.writer(open(outpath,'w',encoding='utf8', newline = ''))
for app in apps:
found = False
for region in app[4]:
if my_country == region:
found = True
if found:
output.writerow([app[0],app[1],app[2],'Available from your local app store'])
else:
output.writerow([app[0],app[1],app[2],app[4]])
print('Done! CSV can be found at ' + outpath)
def getIOSApps(fonts_list):
#iOS_apps: [Title, Developer, Web URL, [fonts], [paths]]
iOS_apps = []
app_titles = []
for font in fonts_list:
if font['AppPlatform'] == 'iOS' and font['Title'] not in app_titles:
app_titles.append(font['Title'])
app_developer = ''
app_weburl = ''
if len(app_titles) > 0:
for app in app_titles:
#app_fonts_check holds unique fonts by filename
app_fonts_check = []
app_fonts = []
app_fonts_paths = []
for font in fonts_list:
if font['AppPlatform'] == 'iOS' and font['Title'] == app and font['FontFileName'] not in app_fonts_check:
app_developer = font['AppDev']
app_weburl = font['AppURL']
app_fonts.append(font)
app_fonts_check.append(font['FontFileName'])
app_fonts_paths.append(str(os.path.dirname(font['Path'])))
iOS_apps.append([app,app_developer,app_weburl,app_fonts,app_fonts_paths])
return iOS_apps
def getAndroidApps(fonts_list):
#android_apps: [Title, Developer, Web URL, [fonts], [paths]]
android_apps = {}
amazon_apps = {}
for font in fonts_list:
if font['AppPlatform'] == 'Android':
if 'Amazon' in font['UseCase']:
dict = amazon_apps
else:
dict = android_apps
if font['Title'] in dict:
if font['FontFileName'] not in dict[font['Title']][4]:
dict[font['Title']][2].append(font)
dict[font['Title']][3].append(str(os.path.dirname(font['Path'])))
dict[font['Title']][4].append(font['FontFileName'])
else:
dict[font['Title']] = [font['AppDev'], font['AppURL'], [font], [str(os.path.dirname(font['Path']))], [font['FontFileName']]]
return android_apps, amazon_apps
def getWebsites(fonts_list, usecase):
#websites: [Title, [fonts]]
websites = {}
for font in fonts_list:
if font['UseCase'] == usecase:
if font['Title'] not in websites:
websites[font['Title']] = []
if font not in websites[font['Title']]:
websites[font['Title']].append(font)
return websites
#return list of fonts as well as websites using no fonts per scraper
def readScrapeResults(scrape_results_path):
scrape_data = []
fonts_list = []
websites_no_wf = []
redirectedURLs = {}
with open(scrape_results_path, newline='',encoding='utf-8') as f:
reader = csv.reader(f)
for row in reader:
scrape_data.append(row)
for row in scrape_data[1:]:
redirectedURLs[row[0]] = row[4]
#filter out errors from scrape results
if row[1] =='':
#filter out No WF sites
if row[2] !='':
#font should either be readable or a MT-hosted WF
fontData = initFontData()
#check for MT-hosted WF (limited info is available for such a font)
if 'fast.fonts.net' in row[5]:
fontData['Name'] = row[5][30:72]
fontData['Family'] = 'Monotype WFS hosted web font'
fontData['Foundry'] = 'Monotype WFS'
fontData['Enforce'] = 'Yes - MT WFS - Check Subscription Details'
fontData['WhyEnforce'] = 'fast.fonts.net in row[5]'
fontData['VerifiedDomain'] = row[2]
fontData['Title'] = row[0]
fontData['UseCase'] = 'Web Font'
remarks = ['None']
#not a MT font, full data available
else:
filename = row[5].split('/')[-1]
if 'typekit' in row[5]:
if 'FontShop' in row[6]:
fontData['Name'] = 'Typekit hosted FontShop web font: ' + str(row[9])
elif len(row[10]) > 2:
fontData['Name'] = row[10]
else:
fontData['Name'] = 'Typekit hosted web font'
elif row[10] == '.':
fontData['Name'] = filename
elif 'FontShop' in row[6]:
if len(row[10]) == 27:
fontData['Name'] = row[9]
elif row[9] == 'Web FontFont' and len(row[10]) == 6:
fontData['Name'] = row[13].split(' ')[0]
else:
fontData['Name'] = filename
elif row[10] != '':
fontData['Name'] = row[10]
else:
fontData['Name'] = filename
fontData['FontFileName'] = filename
fontData['Copyright'] = row[6]
fontData['Trademark'] = row[13]
fontData['Family'] = row[7]
fontData['Subfamily'] = row[8]
fontData['LicenseDesc'] = row[19]
fontData['LicenseURL'] = row[20]
fontData['UniqueID'] = row[9]
fontData['Misc1'] = row[29]
fontData['Version'] = row[11]
fontData['Manufacturer'] = row[14]
fontData['Designer'] = row[15]
fontData['DesignerURL'] = row[18]
fontData['VendorURL'] = row[17]
fontData['WebPath'] = row[5]
fontData['UseCase'] = 'Web Font'
fontData['Title'] = row[0]
fontData['VerifiedDomain'] = row[2]
fontData['LicenseIndicator'] = row[3]
if 'cloudfront.net' in fontData['Title']:
fontData['UseCase'] = 'Digital Ad'
checkFontFoundry(fontData)
#remarks will revert 'Enforce' key if license indicator is present
fontData['Remarks'] = getRemarks(fontData)
fonts_list.append(fontData)
else:
websites_no_wf.append(row[0])
return [fonts_list, websites_no_wf, redirectedURLs]
def getUseCase(font_path):
p = Path(font_path)
use_case = ''
for i in range(len(p.parts)):
if 'app_research' in p.parts[i]:
use_case = 'Mobile App'
break
elif 'web_research' in p.parts[i]:
use_case = 'Web Font'
break
elif 'ad_research' in p.parts[i]:
use_case = 'Digital Ad'
break
elif 'pdf_research' in p.parts[i]:
use_case = 'PDF'
break
elif 'amazon_research' in p.parts[i]:
use_case = 'Mobile App Amazon'
break
return use_case
#def validateScrape(input_urls, export_data):
def getScrapeErrors(scrape_results_path):
scrape_data = []
scrape_errors = []
with open(scrape_results_path, newline='',encoding='utf-8') as f:
reader = csv.reader(f)
for row in reader:
scrape_data.append(row)
#remove header and subset for uniqueness
scrape_data = scrape_data[1:]
scrape_data = [list(x) for x in set(tuple(x) for x in scrape_data)]
for row in scrape_data[1:]:
if row[1] != '':
scrape_errors.append([row[0],row[1]])
scrape_errors = [list(x) for x in set(tuple(x) for x in scrape_errors)]
return scrape_errors
def checkMissedWebsites(input_websites_path, scrape_results_path):
input_websites = []
scrape_websites = []
missed_websites = []
input_websites_clean = []
with open(input_websites_path, newline='',encoding='utf-8') as f:
reader = csv.reader(f)
for row in reader:
input_websites.append(str(row)[2:-2])
with open(scrape_results_path, newline='',encoding='utf-8') as f:
reader = csv.reader(f)
for row in reader:
scrape_websites.append(str(row[0]))
#regex to replace 'http://www.' etc to match form of web scrape output
#may need to check separately for regex5 pattern as this could create false positives for websites such as e.g. 'http://www.mystorewww.com'
regex1 = re.compile('https://www.')
regex2 = re.compile('http://www.')
regex3 = re.compile('https://')
regex4 = re.compile('http://')
regex5 = re.compile('www.')
for input_website in input_websites:
input_website = re.sub(regex1, '', input_website)
input_website = re.sub(regex2, '', input_website)
input_website = re.sub(regex3, '', input_website)
input_website = re.sub(regex4, '', input_website)
input_website = input_website.split('/',1)[0]
input_websites_clean.append(input_website)
for input_website in input_websites_clean:
missed = True
for scrape_website in scrape_websites:
if input_website in scrape_website:
missed = False
if missed:
missed_websites.append(input_website)
#remove duplicates
missed_websites = set(missed_websites)
return missed_websites
def getRedirects(scrape_results_path):
#2 types of redirects- website redirects and the scraper crawling outside the provided domain
scraped_websites = []
redirects = []
redirects.append(['',''])
redirects_conf = []
with open(scrape_results_path, newline='',encoding='utf-8') as f:
reader = csv.reader(f)
for row in reader:
scraped_websites.append(row)
for website in scraped_websites[1:]:
website_redir = [str(website[0]), str(website[4]), 'redir']
website_crawl = [str(website[0]), str(website[2]), 'crawl']
if len(website_redir[1]) >0 and website_redir[0] not in website_redir[1] and website_redir not in redirects:
redirects.append(website_redir)
elif len(website_crawl[1]) > 0 and website_crawl[0] not in website_crawl[1] and website_crawl not in redirects:
redirects.append(website_crawl)
redirects = redirects[1:]
#create checklist of redirects for confirmation
t = []
v = []
for redirect in redirects:
t.append(redirect[0] + ' || ' + redirect[1])
v.append(True)
my_dialog = dialog.Dialog(title = 'Verify Redirects ' + SCRIPT_VERSION, cancellable = True)
cl = dialog.Checklist(titles = t, values = v, height = 500)
my_dialog.add(cl)
if dialog.show(my_dialog):
redirects_conf = list(zip(redirects, cl.values))
outpath = scrape_results_path.split('.',-1)[0] + '_validated.csv'
output = csv.writer(open(outpath,'w',encoding='utf8', newline = ''))
for website in scraped_websites:
flag = True
website_check1 = [str(website[0]), str(website[4])]
website_check2 = [str(website[0]), str(website[2])]
for redir in redirects_conf:
redir_check = [redir[0][0], redir[0][1]]
redir_type = redir[0][2]
if website_check1 == redir_check and redir[1] == False:
flag = False
elif website_check2 == redir_check and redir[1] == False:
flag = False
elif website_check1 == redir_check and redir[1] == True and redir_type == 'redir':
website[0] = website[4]
flag = False
output.writerow(website)
elif website_check2 == redir_check and redir[1] == True and redir_type == 'crawl':
website[0] = website[2]
flag = False
output.writerow(website)
if flag:
output.writerow(website)
else:
outpath = scrape_results_path.split('.',-1)[0] + '_redirects.csv'
output = csv.writer(open(outpath,'w',encoding='utf8', newline = ''))
output.writerow(['Input Domain','Scraped Domain'])
for redirect in redirects:
output.writerow([redirects[0],redirects[1]])
print('Check list canceled. A CSV file of redirects has been saved here: ' + outpath)
'''
def RemoveRedirects(scrape_results_path, validated_redirects_path):
scraped_websites = []
redirects = []
with open(scrape_results_path, newline='',encoding='utf-8') as f:
reader = csv.reader(f)
for row in reader:
scraped_websites.append(row)
with open(validated_redirects_path, newline='',encoding='utf-8') as f: