From phone prefixes to regular expressions - transform

I have a list of phone prefixes (about 50k) and I would like to pass them to regular expressions to reduce the number of lines.
Is there any tool that does it automatically? Does anyone know any script that will do it for me (php, javascript, python, etc), or how can I do that?
To better understood.
I have this..
Prefix
Country
62
INDONESIA
6221
INDONESIA (JAKARTA)
6222
INDONESIA (OTHER CITIES)
62251
INDONESIA (OTHER CITIES)
6231
INDONESIA (OTHER CITIES)
62341
INDONESIA (OTHER CITIES)
62361
INDONESIA (OTHER CITIES)
62411
INDONESIA (OTHER CITIES)
6261
INDONESIA (OTHER CITIES)
62778
INDONESIA (OTHER CITIES)
628
INDONESIA MOBILE
6281
INDONESIA MOBILE
6282
INDONESIA MOBILE
6283
INDONESIA MOBILE
6285
INDONESIA MOBILE
6286
INDONESIA MOBILE
6287
INDONESIA MOBILE
6288
INDONESIA MOBILE
62877
INDONESIA MOBILE XL
62878
INDONESIA MOBILE XL
62879
INDONESIA MOBILE XL
And I want to reduce it to something like this...
Prefix
Country
^62\[0-9\]+$
INDONESIA
^6221\[0-9\]+$
INDONESIA (JAKARTA)
^62(3 | 6)1\[0-9\]+$
INDONESIA (OTHER CITIES)
^623(4 | 6)1\[0-9\]$
INDONESIA (OTHER CITIES)
^6222\[0-9\]+$
INDONESIA (OTHER CITIES)
^662251\[0-9\]+$
INDONESIA (OTHER CITIES)
^62411\[0-9\]+$
INDONESIA (OTHER CITIES)
^62778\[0-9\]+$
INDONESIA (OTHER CITIES)
^628(1|2|3|5|6|7|8)\[0-9\]+$
INDONESIA MOBILE
^6287(7|8|9)\[0-9\]+$
INDONESIA MOBILE XL
Thanks

Not sure, what is the end goal yet, but if you are generating the regexp's from the list, why worry about optimizing the length of the regexp and not just letting the regexp-compiler do the optimization. Example in python:
prefixes = ["6222", "62251", "6231", "62341", "62361", "62411", "6261"]
regex_as_str = "^("+"|".join(prefixes)+")\d+$" # Creates "^(6222|62251|6231|62341|62361|62411|6261)\d+$"
regex = re.compile(regex_as_str)

Related

ValueError: k must be less than or equal to the number of training points

I am trying BerTopic on a cluster of sentences. I have actually employed Agglomerative clustering using Bert sentence embeddings, the result has many clusters one of them is this
docs=["PARIS:France’s trade unions called for mass protests and strikes over pension reform that have brought much of the country to a halt to carry on next week, piling more pressure on President Emmanuel Macron.Commuters faced severe disruption getting to work on Friday, hospitals have been left understaffed and Paris City Hall said dozens of schools in the capital would stay closed, as unions dug in over Macron’s plans to streamline one of the developed world’s most generous pension systems.Transport workers went on strike on Thursday and took to the streets – joined by teachers, doctors, police, firemen and civil servants. Smoke and tear gas swirled through parts of Paris and Nantes as protests turned violent.Union leaders said public workers should maintain their industrial action until Tuesday when they urged members to flood the streets once again.“Unions will meet on Tuesday evening to decide on our next actions if by then Macron and (Prime Minister) Edouard Philippe has not reversed course and opened negotiations,” Catherine Perret of the hard-left CGT union told reporters.The strike pits Macron, a 41-year-old former investment banker who took office in 2017 on a promise of opening up France’s highly regulated economy, against powerful unions who say he is set on dismantling worker protections.“We’re going to protest for a week at least, and at the end of that week it’s the government that’s going to back down,” said 50-year-old Paris transport employee Patrick Dos Santos.The outcome depends on who blinks first – the unions who risk losing public support if the disruption goes on for too long, or the president whose two-and-a-half years in office have been rocked by waves of social unrest.Macron’s pension tsar Jean-Paul Delevoye is due to hold talks with the unions on Monday before the prime minister presents the broad outlines of the proposal to the public mid-week.Education Minister Jean-Michel Blanquer said far-reaching reform was needed to put the generous pension system on a sustainable footing. Fewer teachers went on strike on Friday, education ministry data showed.“It would be much easier for us to do nothing,” Blanquer told BFM TV. “We could see through this five-year term without enacting deep reform. But if every presidency reasons in this way, our children will not have an acceptable pension system.”Police had used tear gas in central Paris on Thursday afternoon when hooded protesters on the fringes of the trade unions’ march threw fireworks at officers, ransacked bus stops, and set fire to rubbish bins.More than 800,000 people rallied in protests countrywide on Thursday. Union leaders put the numbers higher.“There’s a noise in the streets, I hope the windows of the Elysee are open,” said Philippe Martinez, secretary-general of the CGT union, referring to the president’s office.Macron wants to simplify the unwieldy pension system, which comprises more than 40 different plans. Rail workers and mariners can, for instance, retire up to a decade earlier than the average worker.The president says the system is unfair and too costly and that the French will have to work longer, though he appears reluctant to simply raise the retirement age of 62.One alternative is to curb benefits for those who stop working before 64 and give a benefits boost to those who leave later.",
"The French -- and particularly Parisians -- are face to face with what may be the largest strike in the country's history.On the heals of the Yellow Vest protests, employees of various sectors are preparing to go on indefinite strike beginning Thursday to protest pension reforms by the government of French President Emmanuel Macron.The walkout was sealed when the government announced its determination to implement pension reform despite pushback.According to France’s National Institute of Statistics and Economic Studies, Macron has further fueled the sense of anger and rebellion among French people against their presidents, with his economic policies that have given the wealthy a greater share of national income since his inauguration on May 17, 2017.He has been facing the biggest crisis since the yellow vest protests.The reform would lift the privileges granted to civil servants and gradually increasing the retirement age from 62 to 64. It is expected to adversely affect many sectors.Long list of strikersAmong the strikers will be employees of national carrier Air France, state-owned Parisian public transport operator RATP, electricity company EDF that is largely owned by the government, state-owned national railway firm SNCF, and automobile manufacturer Renault.Police, healthcare professionals, teachers, lawyers, taxi and freight drivers, postal workers, farmers, civil servants, refinery workers and students will also participate.Over half of all schools across the country will be suspended, while nearly all commuter trains and buses will halt and or work in intermittently. Air France will cancel 30% of its flights.The Yellow Vest protests started Nov. 17, 2018 in reaction to rising fuel costs and economic injustice, later spiraling into deadly anti-government riots.Protesters used yellow vests, part of the standard safety kit in French cars, to make their members more easily visible.The demonstrations left 11 dead and more than 4,000 injured including protesters and the police, according to government figures.Activists claim that 24 protesters were blinded in one eye and that five lost one of their hands.At least some 8,400 people have been arrested since the beginning of the Yellow Vest protests, and 2,000 were remanded into custody.A total of 17 protestors were arrested in Toulouse and five people -- two police and three civilians -- were injured.",
"PARIS-The Eiffel Tower shut down, France’s vaunted high-speed trains stood still and several thousand people protested in Paris as unions launched open-ended, nationwide strikes Thursday over the government’s plan to overhaul the retirement system.Paris authorities barricaded the presidential palace and deployed 6,000 police as activists - many in yellow vests representing France’s year-old movement for economic justice - gathered in the capital in a mass outpouring of anger at President Emmanuel Macron and his centerpiece reform.Unions and their supporters fear that the changes to how and when workers can retire will threaten the hard-fought French way of life. Macron himself remained “calm and determined” to push it through, according to a top presidential official.The Louvre Museum warned of strike disruptions, and subway stations across Paris shut their gates. Many visitors - including the U.S. energy secretary - canceled plans to travel to one of the world’s most-visited countries amid the strike. Unprepared tourists discovered historic train stations standing empty Thursday, with about nine out of 10 of high-speed TGV trains canceled. Signs at Paris’ Orly Airport showed “canceled” notices, as the civil aviation authority announced 20% of flights were grounded.Some travelers showed support for the striking workers, but others complained about being embroiled in someone else’s fight. “I had no idea about the strike happening, and I was waiting for two hours in the airport for the train to arrive and it didn’t arrive,” said vacationer Ian Crossen, from New York. “I feel a little bit frustrated. And I’ve spent a lot of money. I’ve spent money I didn’t need to, apparently.”Vladimir Madeira, a Chilean tourist vacationing in Paris, said the strike has been “a nightmare.” He hadn’t heard about the protest until he arrived, and transport disruptions foiled his plans to travel directly to Zurich.Beneath the closed Eiffel Tower, tourists from Thailand, Canada and Spain echoed those sentiments. Bracing for possible violence along the route of the Paris march, police ordered all businesses, cafes and restaurants in the area to close. Authorities banned protests in the more sensitive neighborhoods around the Champs-Elysees avenue, presidential palace, parliament and Notre Dame Cathedral.Police carried out security checks of more than 6,000 people arriving for the protest and detained 65 even before it started. Embassies warned tourists to avoid the protest area. The mood was impassioned in the crowd massed on Boulevard Magenta in eastern Paris.Health workers showed up to decry conditions in hospitals. Students pointed to recent student suicides and demanded government action. Environmentalists emphasized that climate justice and social justice are one and the same. And young and old roundly condemned the new retirement plan, which they fear would take money out of their pockets and reduce the period of repose the French expect in the last decades of their lives.Eric Mettling, who joined the yellow vests at the start of their movement, said the general strike had brought together social movements across France in a manner unprecedented in recent memory to denounce “the social crisis.”Skirmishes broke out between police firing tear gas and protesters throwing flares at a protest in the western French city of Nantes, and thousands of red-vested union activists marched through cities from Marseille on the Mediterranean to Lille in the north.Lacking public transport, commuters used shared bikes or electric scooters despite near-freezing temperatures. Many workers in the Paris region worked from home or took a day off to stay with their children, since 78% of teachers in the capital were on strike.The big question is how long the strike will last. Transport Minister Elisabeth Borne said she expects the travel troubles to be just as bad Friday, and unions said they’ll maintain the Paris subway system strike at least through Monday. Public sector workers fear Macron’s reform will force them to work longer and shrink their pensions. Some private sector workers share their worries, while others welcome the reform.Joseph Kakou, who works an overnight security shift in western Paris, walked an hour to get home to the eastern side of town Thursday morning. “It doesn’t please us to walk. It doesn’t please us to have to strike,” Kakou told The Associated Press. “But we are obliged to, because we can’t work until 90 years old.”To Macron, the retirement reform is central to his plan to transform France so it can compete globally in the 21st century. The government argues France’s 42 retirement systems need streamlining. While Macron respects the right to strike, he “is convinced that the reform is needed, he is committed, that’s the project he presented the French in 2017” during his election campaign, the presidential official said. The official was not authorized to be publicly named.After extensive meetings with workers, the high commissioner for pensions is expected to detail reform proposals next week, and the prime minister will release the government’s plan days after that.",
"Protesters mobilized across France on Thursday in a nationwide strike challenging President Emmanuel Macron’s controversial pension reform plans.The Interior Ministry said 806,000 people took part, while labor unions put the number at nearly 1.5 million.Some 250,000 people took part in the protests in Paris, where police used smoke bombs to disperse the crowd.The unlimited strike impacted all public transport systems in the country, according to local media reports.A total of 90 people have been arrested so far in Paris, police said.Some train, subway and bus services were canceled and many schools were closed while the law and order situation led to the cancelation of 20% of flights to the country.In a tweet, the Paris Police Department said it had conducted 6,476 checks. Labor unions said the strike will continue until Monday.The Gare du Nord, a station of the SNCF railway network in Paris, was almost empty in the morning, according to broadcaster France 24.Protesters, however, made their way to the Gare du Nord in the afternoon to attend the main march to Place de la Nation square.They included police, healthcare professionals, teachers, lawyers, taxi and freight drivers, postal workers, farmers, civil servants, refinery workers and students, according to the Le Monde daily.The walkout came after the government announced its determination to implement pension reform despite a nationwide outcry.According to France’s National Institute of Statistics and Economic Studies, Macron has further fueled the sense of anger and rebellion among French people against their president with his economic policies that have given wealthy people a greater share of national income since his inauguration on May 17, 2017.He has been facing the biggest crisis since the beginning of the Yellow Vest protests in October last year.Proposed reformFrance currently has 42 different pension programs for different sectors, but the government proposed to unify them into one pension scheme.France’s current program is based on the principle of solidarity between generations under which the working population finances the pensioners of that year.But due to the aging population, fewer people are paying into the current system.To fix this, the government introduced a point-based system that would compensate workers with pension points for every day they work or every euro they contribute.The reform would lift the privileges granted to civil servants and gradually increase the retirement age from 62 to 64, a move expected to adversely affect many sectors.Workers will get a full pension if they retire at the age of 64. If they retired before, they would lose 5% of their pensions for every year they retire early.They would also gain a 5% increase in their pensions for every year if they retire after the age of 64.The demonstrations and strikes have been supported by numerous labor and police unions as well as the Yellow Vests.Macron paused his overseas visits for a while to focus on a solution to the problems caused by the strikes and demonstrations.",
"Paris-A strike over planned pension reforms that paralysed France on Thursday has entered its second day.Several unions, including rail and metro workers, voted to extend the strike action, meaning another day of major disruptions to key services.It comes after more than 800,000 people protested on Thursday, with violent clashes reported in a number of cities.Workers are angry about planned pension reforms that would see them retiring later or facing reduced payouts.France currently has 42 different pension schemes across its private and public sectors, with variations in retirement age and benefits. President Emmanuel Macron says his plans for a universal points-based system would be fairer, but many disagree.Rail workers voted to extend their strike through Friday, while unions at the Parisian bus and metro operator said their walkout would continue until at least Monday.Numerous rush-hour trains into Paris were cancelled on Friday and 10 out of 16 metro lines were closed, while others ran limited services, Reuters news agency reports.Traffic jams of more than 350km (217 miles) were reported on major roads in and around the capital.A number of flights have also been disrupted, while many schools are expected to remain shuttered and hospitals understaffed. Protesters sang songs against President Macron in ParisMr Macron’s government has reportedly made plans to deal with the strike action at the weekend.Some trade union leaders have vowed to strike until Mr Macron abandons his campaign promise to overhaul the retirement system.“We’re going to protest for a week at least, and at the end of that week it’s the government that’s going to back down,” 50-year-old Paris transport employee Patrick Dos Santos told Reuters.What happened on Thursday?French police gave the figure of 800,000 people taking to the streets across the country, including 65,000 in Paris. Union leaders put the numbers higher, with the CGT union saying 1.5m people turned out across France.The disruption meant popular tourist sites in Paris, including the Eiffel Tower, were closed for the day and usually busy transport hubs like the Gare du Nord were unusually quiet.",
"Paris (AFP): France was on Saturday expecting its most serious nationwide strike in years to paralyse the country over the weekend, with unions warning the turmoil would last well into next week.",
"PARIS: The French government on Friday expressed determination to plough ahead with far-reaching pension reforms in the face of the biggest strikes in years, which have brought public transport in much of the country to a standstill.The strikes, which began on Thursday, have seen most high-speed trains cancelled, flights affected and most of the Paris metro shut down in a major challenge to the ambitious reform agenda of President Emmanuel Macron.The turmoil is expected to continue over the weekend and through until at least Tuesday when unions have called more nationwide protests to follow mass rallies on Thursday that brought over 800,000 people onto the streets.With Macron not yet speaking publicly about the strikes and seeking for now to rise above the fray, Prime Minister Edouard Philippe insisted that the government would not abandon a plan which would require the French “to work a bit longer.” He pledged to work with trade unions to introduce a single “fairer”, points-based pension scheme for all, scrapping the 42 more advantageous plans currently enjoyed by train drivers, soldiers and a host of other workers in the process.The centre-right premier added that the government was “very determined” to implement the reform, adding he did not believe the French would always accept a situation where some retire earlier, and with more money than others doing comparable jobs.But he emphasised that the changes, which he said would be unveiled on Wednesday, would be introduced “progressively, without harshness”. “My logic will never be one of confrontation,” he said.Dozens of trains, metros and flights were cancelled, many schools were again closed or offering only daycare, and four of the country’s eight oil refineries remained blocked on Friday.Rail operator SNCF has already halted ticket sales through the weekend, with 90 percent of high-speed TGV trains again cancelled on Friday and little improvement expected over the weekend.Half of the Eurostar trains between Paris and London were dropped, and just two of three Thalys trains serving Paris, Brussels and Amsterdam were running.“I was supposed to take a train to Metz (northeast France), I reserved my ticket three days ago but it’s been cancelled and I’ve gotten no information,” Rachel Pallamidessi said at a deserted station in the city of Strasbourg.Several airlines cancelled flights as air traffic controllers walked off the job, with Air France cancelling 30 percent of domestic flights and 10 percent of nearby international routes.In Paris, nine of the capital’s 16 metro lines were shut while many others were running only during rush hours, prompting commuters to turn to bicycles, electric scooters and other alternatives or to work from home.It remains to be seen if the protests will match the magnitude of the 1995 strikes against pension overhauls when France was paralysed for three weeks from November to December, ultimately forcing the government to back down. The walkout is the latest test of Macron’s mettle after months of protests from teachers, hospital workers, police and firefighters, capping a year of social unrest triggered by the “yellow vest” protest movement.Unions say Macron’s proposal for a single pension system would force millions of people in both the public and private sectors to work well beyond the official retirement age of 62.At least 800,000 took part in rallies around the country on Thursday, according to the interior ministry, one of the biggest demonstrations of union strength in nearly a decade.Another day of strikes and rallies has been called for Tuesday, a day after union leaders are to meet again with government officials over the pension reform.“There were lots of people on strike, now we need even more if we want to influence these decisions,” Philippe Martinez of the hard-line CGT union told LCI television.While most of the rallies were peaceful, police fired tear gas to disperse dozens of black-clad protesters smashing windows and throwing stones during the Paris march, with one construction trailer set on fire.Several dozens of people were arrested, and three journalists were injured after reportedly being hit by tear gas or stun grenades, including a Turkish journalist who was struck in the face.Published in Dawn, December 7th, 2019Copyright © 2019, DawnScribe Publishing Platform",
]
The code is as follows.
from bertopic import BERTopic
# docs=[i for i in all_text if type(i)==str]
# docs=docs.T
topic_model = BERTopic()
topics, probs = topic_model.fit_transform(docs)
Any help is much appreciated
Thanks

openai.error.InvalidRequestError: does not have access to the answers endpoint

When I'm trying to implement the QA system with GPT-3, there is an error occurred:
openai.error.InvalidRequestError: Org org-Ilv48EJDyLWiTc2SJWjOnRaM does not have access to the answers endpoint. Reach out to deprecation#openai.com if you have any questions
My code is:
import openai
openai.api_key = "my-openai-key"
document_list = ["Google was founded in 1998 by Larry Page and Sergey Brin while they were Ph.D. students at Stanford University in California. Together they own about 14 percent of its shares and control 56 percent of the stockholder voting power through supervoting stock. They incorporated Google as a privately held company on September 4, 1998. An initial public offering (IPO) took place on August 19, 2004, and Google moved to its headquarters in Mountain View, California, nicknamed the Googleplex. In August 2015, Google announced plans to reorganize its various interests as a conglomerate called Alphabet Inc. Google is Alphabet's leading subsidiary and will continue to be the umbrella company for Alphabet's Internet interests. Sundar Pichai was appointed CEO of Google, replacing Larry Page who became the CEO of Alphabet.",
"Amazon is an American multinational technology company based in Seattle, Washington, which focuses on e-commerce, cloud computing, digital streaming, and artificial intelligence. It is one of the Big Five companies in the U.S. information technology industry, along with Google, Apple, Microsoft, and Facebook. The company has been referred to as 'one of the most influential economic and cultural forces in the world', as well as the world's most valuable brand. Jeff Bezos founded Amazon from his garage in Bellevue, Washington on July 5, 1994. It started as an online marketplace for books but expanded to sell electronics, software, video games, apparel, furniture, food, toys, and jewelry. In 2015, Amazon surpassed Walmart as the most valuable retailer in the United States by market capitalization."]
response = openai.Answer.create(
search_model="ada",
model="curie",
question="when was google founded?",
documents=document_list,
examples_context="In 2017, U.S. life expectancy was 78.6 years.",
examples=[["What is human life expectancy in the United States?","78 years."]],
max_tokens=10,
stop=["\n", "<|endoftext|>"],
)
print(response)
where "my-openai-key" is the secret key allocated in openai's website.

How to parse all <p> tags within a certain <div> tag?

I am using BeautifulSoup to parse some html page.
I want to get all text information within the <p> tags under this <div id="commentary">
link to image of that html script content which I want to get
When I use find_all to get all of the <p> tags, the list contains only the first one. I used to following code to count the no. of <p> tags present under <div>. You can clearly see from the above image that there are around 19 <p> tags within that highlighted <div> tag, still my code prints out 1.
content = soup.find('div', attrs={'class':'company-profile'})
points = content.find('div', attrs={'id':'commentary'})
count = 0
for point in points.find_all('p'):
count = count + 1
print(count)
print(points.text)
I don't know why is this happening and why the find_all method wont return the complete list.
I also tried using the points.text to print all of the text within <div id="commentary"> tag, but it prints contents of first <p> tag only.
(mlenv) chirag#debian10:~/ML/Finaments$ python main.py
<class 'bs4.element.Tag'>
State Bank of India is a Fortune 500 company. It is an Indian Multinational, Public Sector banking and financial services statutory body headquartered in Mumbai. It is the largest and oldest bank in India with over 200 years of history.#
1
1
Ratios (Q3FY21)
Capital Adequacy Ratio - 14.50%
Net Interest Margin - 3.34%
Gross NPA - 4.77%
Net NPA - 1.23%
CASA Ratio - 45.15%#
(mlenv) chirag#debian10:~/ML/Finaments$ ^C
(mlenv) chirag#debian10:~/ML/Finaments$
Those 1's are the from print(count) and then it only prints the content of first <p> tag from print(points.text).
I have just started using beautifulsoup, please help me.
You can go after the direct url that has that info. You'll need to pass in there the correct cookies and csrf tokens though:
import requests
from bs4 import BeautifulSoup
url = 'https://www.screener.in/wiki/company/3188/commentary/'
headers= {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
'referer': 'https://www.screener.in/company/SBIN/consolidated/',
'x-csrftoken': 'E8zDjm7CtmSqCM2B9rTYPXTcPMJ22w2oynWzWzT4bCgAIaKkt4DmrirBSEPdCP0W',
'cookie': '_gcl_au=1.1.69436223.1621345270; _ga=GA1.2.2056656539.1621345271; _gid=GA1.2.1452432592.1621345271; csrftoken=E8zDjm7CtmSqCM2B9rTYPXTcPMJ22w2oynWzWzT4bCgAIaKkt4DmrirBSEPdCP0W; sessionid=mrdcmrlqpe72dqjrqgtrb2m2v375sjv0; _gat_UA-2456523-7=1'}
response = requests.post(url, headers=headers)
soup = BeautifulSoup(response.text, 'html.parser')
count = 0
for point in soup.find_all('p'):
count = count + 1
print(count)
print(soup.text)
Output:
19
Ratios (Q3FY21)
Capital Adequacy Ratio - 14.50%
Net Interest Margin - 3.34%
Gross NPA - 4.77%
Net NPA - 1.23%
CASA Ratio - 45.15%#
Branch Network
Presently, the bank operates a network of 22,330 branches and ~58,000 ATMs across India. It also operates ~71,000 business correspondent outlets across India.#
Market Share
The bank has a market share of 22.84% in deposits and 19.69% share in advances in India. It has a strong customer base of ~45 crore customers.#
Loan Book
Retail loans account for 39% of the loan book, followed by corporate (37%), SME (14%) and Agriculture (10%).#
Retail Book - Home loans account for 68% of the retail book, followed by xpress credit (22%), auto loans (9%), personal gold loans (2%) and others (9%).#
Exposure
The bank has a well-diversified loan book exposed to various sectors. Top sectors include home loans (23%), infrastructure (15%), services (12%) and agriculture (10%).
~75% of the corporate advances are rated A and better ratings from rating agencies. 38% of the corporate book accounts for PSUs & Govt. departments.#
Segmental NPAs
Presently, the total NPAs of the bank stands at 1,17,244 crores. agriculture segment accounts for the major ratio of NPAs i.e. 13.71% of all loans are NPA. Corporate segment accounts for 59,400 crores worth of NPAs i.e. 51% of total NPAs of the bank.#
International Business
The bank has a global footprint with a network of 233 branches/offices in 32 countries.# It has presence in USA, Canada, Brazil, Russia, Germany, France, Turkey, Australia, Bangladesh, Nepal, Sri Lanka and other countries.#
Presently, Overseas business accounts for 3% of total deposits# and 13% of total advances.#
Government Business
SBI has always been the banker of choice to the government of India and is the market leader in government business. It had turnover of ~52,50,000 lakh crores and commissions of ~3,700 crores from government business in FY20.#
Financial Inclusion Business
The bank has ~71,000 BC outlets which has primary focus on financial inclusion customers.# The bank accounts for 40% of all PMJDY accounts i.e. more than 12 crore accounts.# Presently, the deposits from PMJDY accounts are ~42,500 crores i.e. 1.2% of total deposits of the bank.
Digital Metrics
Increasing digitization resulted in ~40% of asset accounts and ~60% of liability customers added via digital channels in FY21.# 67% of all transactions were initiated through digital channels in 2020 which is up from 58% in the previous year.#
Subsidiaries Operations
The bank owns various subsidiaries which are engaged in related business activities :-
1. SBI Capital Markets Ltd (100% stake) - SBICAP is a leading investment banker, offering investment banking and corporate advisory services to clients across three product categories i.e. project advisory and structured finance, equity capital markets and debt capital markets.
This company further has wholly owned subsidiaries in related businesses viz. SBICAP Securities, SBICAP Trustee Co., SBICAP Ventures & others.#
2. SBI DHFI Ltd (72% stake) - It is a primary dealer and supports the book building process and provide depth and liquidity to secondary markets in G-Sec. It also deals in money market instruments, non G-Sec debt instruments, amongst others.#
3. SBI Cards and Payment Services Ltd (69% stake) - It is a non-banking financial company that offers extensive credit card portfolio to individual cardholders and corporate clients. It has diversified customer acquisition network that enables to engage prospective customers across multiple channels.#
The IPO of SBI Cards was launched in March 2020 wherein the company sold ~13 crore equity shares for a consideration of ₹10,350 crores.#
4. SBI Life Insurance Co. Ltd (57.6% stake) - It is one of the leading life insurance company in India which offers a wide range of individual and group insurance solutions that meet various life stage needs of customers.#
5. SBI Funds Management Pvt Ltd (63% stake) - It is a JV between SBI and AMUNDI (France). It is an asset management company with the fastest CAGR of 33% as against industrial average of 14% in the last 3 years.#
6. SBI General Insurance Company Ltd (70% stake) - It is a general insurance company which focuses on profitable growth in banc-assurance channel along with other distribution channels and line of businesses. It is first non-life insurance company in India to cross 6,000 crores in a decade of operations.#
Amalgamation of Associate Banks
In March 2017, the bank acquired its 5 associate state banks and Bharatiya Mahila Bank by allotting ~13.5 crore equity shares of SBI.#

European Union Specific ISO-1366-1 Country Codes for GeoIP

With GDPR looming I put together a stupid script to block all European Union countries from accessing a site. The trouble is I couldn't find an exhaustive list of the EU country codes.
There is a gist to get me started, however, there are comments that have not been implemented, so it's unclear what a complete list might look like.
https://gist.github.com/henrik/1688572
Has anyone got the complete list of European Union country codes including the Outer Most Territories, Special Cases and anything else I may have missed?
This what I have managed to put together so far.
EU 28
AT, Austria
BE, Belgium
BG, Bulgaria
HR, Croatia
CY, Cyprus
CZ, Czech Republic
DK, Denmark
EE, Estonia
FI, Finland
FR, France
DE, Germany
GR, Greece
HU, Hungary
IE, Ireland, Republic of (EIRE)
IT, Italy
LV, Latvia
LT, Lithuania
LU, Luxembourg
MT, Malta
NL, Netherlands
PL, Poland
PT, Portugal
RO, Romania
SK, Slovakia
SI, Slovenia
ES, Spain
SE, Sweden
GB, United Kingdom (Great Britain)
Outermost Regions: Part of EU (OMR)
https://en.wikipedia.org/wiki/Special_member_state_territories_and_the_European_Union#Outermost_regions
GF, French Guiana
GP, Guadeloupe
MQ, Martinique
ME, Montenegro
YT, Mayotte
RE, Réunion
MF, Saint Martin
No Code, Azores
No Code, Canary Islands
No Code, Madeira
Special Cases: Part of EU
https://en.wikipedia.org/wiki/Special_member_state_territories_and_the_European_Union#Special_cases_in_Europe
GI, Gibraltar
AX, Åland Islands
No Code, Büsingen am Hochrhein
No Code, Campione d'Italia and Livigno
No Code, Ceuta and Melilla
No Code, UN Buffer Zone in Cyprus
No Code, Helgoland
No Code, Mount Athos
Overseas Countries and Territories (OCT)
https://en.wikipedia.org/wiki/Special_member_state_territories_and_the_European_Union#Overseas_countries_and_territories
PM, Saint Pierre and Miquelon
GL, Greenland
BL, Saint Bartelemey
SX, Sint Maarten
AW, Aruba
CW, Curacao
WF, Wallis and Futuna
PF, French Polynesia
NC, New Caledonia
TF, French Southern Territories
AI, Anguilla
BM, Bermuda
IO, British Indian Ocean Territory
VG, Virgin Islands, British
KY, Cayman Islands
FK, Falkland Islands (Malvinas)
MS, Montserrat
PN, Pitcairn
SH, Saint Helena
GS, South Georgia and the South Sandwich Islands
TC, Turks and Caicos Islands
Microstates (Not sure how these fit in)
https://en.wikipedia.org/wiki/Microstates_and_the_European_Union
AD, Andorra
LI, Liechtenstein
MC, Monaco
SM, San Marino
VA, Vatican City
Other (Not sure how these fit in)
JE, Jersey
GG, Guernsey
GI, Gibraltar
European Union
EU, European Union (Not sure this is useful, is it kept up to date?)
From this list I ended up with the following .htaccess script to block the European Union from accessing a site.
I should add I have no intention of ever using this, it's was just a good bit of practice configuring apache mods and messing around with GeoIP/MaxMind.
While this case is ridiculous, I still want to implement it correctly, it may be useful for something or someone one day.
Edit
Not that ridiculous apparently, today I have seen about a dozen companies already blocking EU users o_O.
In this particular case, the codes should cover EU country codes that GDPR apply to. Have I missed anything?
.htaccess
MaxMindDBEnable On
MaxMindDBFile DB /opt/GeoIP/GeoLite2-Country.mmdb
MaxMindDBEnv MM_COUNTRY_CODE DB/country/iso_code
SetEnvIf MM_COUNTRY_CODE ^(AT|BE|BG|HR|CY|CZ|DK|EE|FI|FR|DE|GR|HU|IE|IT|LV|LT|LU|MT|NL|PL|PT|RO|SK|SI|ES|SE|GB|GI|AX|PM|GL|BL|SX|AW|CW|WF|PF|NC|TF|AI|BM|IO|VG|KY|FK|MS|PN|SH|GS|TC|IS|LI|NO|EU) BlockCountry
Deny from env=BlockCountry
Updates
GDPR also applies to parts of European Econimic Area (EEA)
IS, Iceland
LI, Liechtenstein
NO, Norway
MaxMind can return EU for some European Union IPs
EU, European Union
Not sure if it completes your list but GDPR applies to all EEA countries including those not in EU i.e. Iceland, Liechtenstein and Norway (IS,LI,NO). Additionally Maxmind may return "EU" for some European IPs.

Determining customary distance unit from ISO 3166 country code

ISO 3166 defines country codes such as GB, US, FR or RU.
I would like a reasonably definitive association from these country codes to the customary unit of measure for distances between places in those countries.
Specifically on iOS and OS X, the country code can be retrieved from NSLocale:
[[NSLocale currentLocale] objectForKey: NSLocaleCountryCode];
NSLocale also provides a way to see if a country uses metric or non metric units:
const bool useMetric = [[[NSLocale currentLocale] objectForKey: NSLocaleUsesMetricSystem] boolValue];
However, this is not sufficient. For example, in Great Britain (GB) the metric system is widely used, but distances between places continue to be officially measured in miles rather than kilometres.
I also faced this problem :-)
Countries which uses Metric system but still use miles :--
1. GB is only exception which still uses miles instead of metric.
Note: Canada also stared using KMs for road transport. Although, Canada still follows miles for train and horse transport
Countries which do not uses Metric System
Liberia, Myanmar and United States of America.
Note: Myanmar (Formerly Burma) is planning to move to metric system. Currently, Myanmar uses its own system different from imperial and metric.
In my app, i check whether country uses imperial or metric.
if (metric) then assign kms for all countries except britan
if (imperial) then assign miles for all countries except Burma
if burma then assign burma unit
if britan then assign miles
A chart showing countries using miles per hour for road speeds is available. It cites Wikipedia's articles on miles per hour as its source, which has the following to say:
These include roads in the United Kingdom,[1] the United States,[2] and UK and US territories; American Samoa,[3] the Bahamas,[4] Belize,[5] British Virgin Islands,[6] the Cayman Islands,[7] Dominica,[8] the Falkland Islands,[9] Grenada,[10] Guam,[11] Burma,[12] The N. Mariana Islands,[13] Samoa,[14] St. Lucia,[15] St. Vincent & The Grenadines,[16] St. Helena,[17] St. Kitts & Nevis,[18] Turks & Caicos Islands,[19] the U.S. Virgin Islands,[20][21] Antigua & Barbuda (although km are used for distance),[22] and Puerto Rico (same as former).[22]
I don't see a way to download this as data keyed from ISO3166 country code, but it's not a huge task to compile one.
I'll leave this answer unaccepted in case a better suggestion is available.
Officially, road distances in the UK are in kilometres, but road signs are in miles. Confusing? Yes! When a road engineer get aplan of a road, everythign is in kiolometres, government statistics are in kilometres, but road signs and car odometers are in miles. See https://en.wikipedia.org/wiki/Driver_location_sign for more info.

Resources