Section 29. Cities and towns may by ordinance or by-law regulate the conducting within their respective limits of entertainments, dances and other diversions and amusements not required by law to be licensed, including the hours of holding the same, by corporations which are subject to section twenty-six, and may affix penalties for breaches thereof not exceeding twenty dollars for each offence, subject as to recovery and disposition to section twenty-one of chapter forty.