2 # -*- coding: utf-8 -*-
4 #This file is part of <name prog> project
7 #Copyright (C) <year> <name|nick>
9 #This program is free software; you can redistribute it and/or
10 #modify it under the terms of the GNU General Public License
11 #as published by the Free Software Foundation; either version 2
12 #of the License, or (at your option) any later version.
14 #This program is distributed in the hope that it will be useful,
15 #but WITHOUT ANY WARRANTY; without even the implied warranty of
16 #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 #GNU General Public License for more details.
19 #You should have received a copy of the GNU General Public License
20 #along with this program; if not, write to the Free Software
21 #Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 #You can contact author by email <my email>
29 dict_folder
= os
.path
.join( os
.path
.abspath('.'), 'dict' )
30 dicts
= {'#fam':open( os
.path
.join( dict_folder
, 'family.txt') ,'r' ),
31 '#name': open( os
.path
.join( dict_folder
, 'name.txt'), 'r')}
33 def parse_argv( argv
):
38 result
.update( {a
: a
[1:-1].split(',') })
41 result
.update( { a
:range( *[ int(i
) for i
in a
[1:-1].split('..')] ) } )
42 if a
.startswith('#fam'):
43 result
.update( {a
:a
} )
44 if a
.startswith('#name'):
45 result
.update( {a
:a
} )
48 def rand_chois_from_dict( tag
= '#name'):
52 f
.seek( random
.randint( 0L, max_pos
) )
54 selected
= f
.readline().replace('\r','').replace('\n','')
57 def main( argv
=['#name','#fam','(м,ж)','[1500..8900]'], __max
= 1024*2, delim
=' ', delim_min_count
=4,delim_max_count
=10):
58 parsed_argv
= parse_argv( argv
)
60 for i
in xrange(__max
):
63 _pa
= parsed_argv
.get(a
)
66 __temp
.append( rand_chois_from_dict( _pa
) )
68 __temp
.append( str(random
.choice( _pa
)) )
69 _delim
= delim
*random
.randint( delim_min_count
, delim_max_count
)
70 result_array
.append( _delim
.join( __temp
) )
71 result
= '\n'.join( result_array
)
75 if __name__
== '__main__':