@ -1,6 +1,8 @@
import sqlite3
from cache_manager import CacheManager
from DetermineOriginGame import get_locations_from_bulbapedia
from bs4 import BeautifulSoup , Tag
import re
def create_encounters_table ( ) :
conn = sqlite3 . connect ( ' pokemon_forms.db ' )
@ -14,6 +16,106 @@ def create_encounters_table():
#conn.commit()
return conn
def extract_routes ( s ) :
# Find all route numbers, including those after "and" or separated by commas
route_pattern = r ' Routes? \ s+((?: \ d+(?:,? \ s+(?:and \ s+)?)?)+) '
route_match = re . search ( route_pattern , s , re . IGNORECASE )
if route_match :
# Extract all numbers from the matched group
numbers = re . findall ( r ' \ d+ ' , route_match . group ( 1 ) )
# Remove the extracted part from the original string
remaining = s [ : route_match . start ( ) ] + s [ route_match . end ( ) : ] . lstrip ( ' , ' )
return numbers , remaining
else :
return [ ] , s
days = [ " Mo " , " Tu " , " We " , " Th " , " Fr " , " Sa " , " Su " ]
times = [ " Morning " , " Day " , " Night " ]
all_games = [
" Yellow " , " Red " , " Blue " ,
" Crystal " , " Gold " , " Silver " ,
" Emerald " , " FireRed " , " LeafGreen " , " Ruby " , " Sapphire " ,
" Platinum " , " HeartGold " , " SoulSilver " , " Diamond " , " Pearl " ,
" Black 2 " , " White 2 " , " Black " , " White " ,
" X " , " Y " , " Omega Ruby " , " Alpha Sapphire " ,
" Ultra Sun " , " Ultra Moon " , " Sun " , " Moon " ,
" Sword " , " Shield " , " Expansion Pass " ,
" Brilliant Diamond " , " Shining Pearl " ,
" Legends: Arceus " ,
" Scarlet " , " Violet " , " The Teal Mask " , " The Hidden Treasure of Area Zero " , " The Hidden Treasure of Area Zero (Scarlet) " , " The Hidden Treasure of Area Zero (Violet) " , " The Teal Mask (Scarlet) " , " The Teal Mask (Violet) " ,
" Unknown " ,
" Pokémon Home " ,
" Pokémon Go " ,
]
def find_match ( search_string , string_array ) :
return next ( ( item for item in string_array if search_string in item ) , None )
def find_all_matches_from_array ( string , array ) :
return [ item for item in array if item in string ]
def extract_bracketed_text ( string ) :
# This pattern matches text within parentheses, including nested parentheses
pattern = r ' \ ((?:[^()]*| \ ([^()]* \ ))* \ ) '
# Find all matches
matches = re . findall ( pattern , string )
# Remove the outer parentheses from each match
return [ match [ 1 : - 1 ] for match in matches ]
def extract_additional_information ( s ) :
soup = BeautifulSoup ( s , ' html.parser ' )
full_text = soup . get_text ( strip = True )
sup_tags = soup . find_all ( ' sup ' )
sup_text = None
details = { }
details [ " days " ] = [ ]
details [ " times " ] = [ ]
details [ " dual_slot " ] = None
details [ " only_one " ] = False
details [ " static_encounter " ] = False
details [ " only_two " ] = False
details [ " extra_text " ] = None
details [ " stars " ] = None
for sup_tag in sup_tags :
sup_text = sup_tag . get_text ( strip = True )
if find_match ( sup_text , days ) :
details [ " days " ] . append ( sup_text )
if find_match ( sup_text , times ) :
details [ " times " ] . append ( sup_text )
bracket_text = extract_bracketed_text ( full_text )
if len ( bracket_text ) > 0 :
if bracket_text [ 0 ] in all_games :
details [ " dual_slot " ] = bracket_text [ 0 ]
if " Only One " in bracket_text :
details [ " only_one " ] = True
details [ " static_encounter " ] = True
if " Only Two " in bracket_text :
details [ " only_two " ] = True
details [ " static_encounter " ] = True
if " ★ " in bracket_text :
details [ " stars " ] = bracket_text
details [ " extra_text " ] = " " . join ( bracket_text )
if sup_text :
return full_text . replace ( sup_text , " " ) , details
else :
return full_text , details
if __name__ == " __main__ " :
cache = CacheManager ( )
@ -33,16 +135,35 @@ if __name__ == "__main__":
gender = form
form = None
encounters_we_aren_t_interested_in = [ " T rade" , " Time C apsule" , " Unobtainable " ]
encounters_to_ignore = [ " t rade" , " time c apsule" , " unobtainable " , " evolve " , " tradeversion " , " poké transfer " , " friend safari " ]
encounter_data = get_locations_from_bulbapedia ( name , form , cache )
for encounter in encounter_data :
print ( f " Found in { encounter } : " )
if len ( encounter_data [ encounter ] ) == 0 :
continue
print_encounter = True
for location in encounter_data [ encounter ] :
if location in encounters_we_aren_t_interested_in :
if location == " " :
continue
if " Evolve " in location :
test_location = location [ " location " ] . strip ( ) . lower ( )
ignore_location = False
for ignore in encounters_to_ignore :
if ignore in test_location :
ignore_location = True
break
if ignore_location :
continue
if " TradeVersion " in location :
continue
print ( f " { location } " )
if print_encounter :
print ( f " Found in { encounter } : " )
print_encounter = False
routes , remaining = extract_routes ( location [ " location " ] . strip ( ) )
print ( f " Routes: { routes } " )
remaining_locations , details = extract_additional_information ( location [ " tag " ] )
print ( f " Remaining: { remaining_locations } " )
print ( f " Details: { details } " )