-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from RockChinQ/feat/random-ad
Feat: add supports for optional ads
- Loading branch information
Showing
5 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import random | ||
import typing | ||
|
||
ads = [] | ||
|
||
rate = 0.01 | ||
|
||
enabled = False | ||
|
||
def generate_ad() -> typing.Generator[str, None, None]: | ||
"""Generate random ad.""" | ||
global ads | ||
global rate | ||
global enabled | ||
|
||
if not enabled: | ||
return | ||
|
||
if len(ads) == 0: | ||
return | ||
|
||
if random.random() < rate: | ||
ad_words = random.choice(ads).split(" ") | ||
|
||
for word in ad_words: | ||
yield word | ||
yield " " |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters